Skip to content

Commit

Permalink
update update :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emre ATAKLI committed Apr 6, 2022
1 parent 41f9707 commit 1c0f1fb
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion calcTimes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <QJsonObject>
#include <QJsonDocument>

extern const QString evkatOfflinePath;
//extern const QString evkatOfflinePath;

double CalcTimes::degToRad(double degree)
{
Expand Down
3 changes: 3 additions & 0 deletions calcTimes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define CALCTIMES_H
#include <QString>
#include <QCoreApplication>

const QString evkatOfflinePath = "/namazVakitFiles/evkatOffline.json";

class CalcTimes
{
private:
Expand Down
13 changes: 4 additions & 9 deletions fetchtimes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <algorithm>

//extern const QString evkatOnlinePath;
//extern const QString evkatOfflinePath;

HttpWindow::HttpWindow(QWidget *parent) : QDialog(parent) {}

HttpWindow::~HttpWindow() = default; // TODO: bu nasıl bir saçmalıktır: default'u niye burda yazmışım, class definition'da yazayım diye oraya alıp burayı tamamen kaldırınca hata verdi.
Expand Down Expand Up @@ -33,13 +36,6 @@ void HttpWindow::downloadFile(QString fileName, QString urlSpec)
{
QUrl url = QUrl::fromUserInput(urlSpec);

// if (QFile::exists(fileName))
// {
// if (QMessageBox::question(this, tr("Overwrite Existing File"), tr("There already exists a file called %1%2. Overwrite?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::No)
// {
// return;
// }
// }
file = openFileForWrite(fileName);
if (!file)
{
Expand All @@ -53,11 +49,10 @@ void HttpWindow::downloadSynchronous(QString fileName, QString urlSpec)
QString directory;
if(fileName == "")
{
// return;
newVersion = true;
directory = QFileDialog::getExistingDirectory(this, tr("Yeni sürümü indireceğiniz klasörü seçin"));
if(directory == "")
directory = applicationDirPath;
return;
fileName = directory + "/PrayerReminder.zip";
}

Expand Down
3 changes: 0 additions & 3 deletions fetchtimes.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class QSslError;
class QNetworkReply;
QT_END_NAMESPACE

extern const QString evkatOnlinePath;
extern const QString evkatOfflinePath;

class HttpWindow : public QDialog
{
Q_OBJECT
Expand Down
10 changes: 4 additions & 6 deletions prayertimesparser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "prayertimesparser.h"
#include "calcTimes.h"

#include <QJsonObject>
#include <QTextStream>
Expand All @@ -7,10 +8,7 @@
#include <QFile>
#include <QDir>

PrayerTimesParser::PrayerTimesParser()
{
loadJson();
}
PrayerTimesParser::PrayerTimesParser() {}

bool PrayerTimesParser::loadJson()
{
Expand All @@ -31,8 +29,6 @@ bool PrayerTimesParser::loadJson()

loadDoc = QJsonDocument::fromJson(saveData);

// QJsonObject object = loadDoc.object();

return true;
}

Expand Down Expand Up @@ -78,6 +74,8 @@ int PrayerTimesParser::vakitleriCikar(QJsonValue value)
}
int PrayerTimesParser::nextDay()
{
loadJson();

QDate dt = QDateTime::currentDateTime().date();

int year = dt.year();
Expand Down
5 changes: 2 additions & 3 deletions prayertimesparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
#include <QJsonDocument>

const QString evkatOnlinePath = "/namazVakitFiles/evkatOnline.json";
const QString evkatOfflinePath = "/namazVakitFiles/evkatOffline.json";

class PrayerTimesParser
{
private:
const QString applicationDirPath = QCoreApplication::applicationDirPath();
bool loadJson();
QJsonDocument loadDoc;
int Min(QString vakit);
bool loadJson();
int kalan(QStringList list);
public:
int nextDay();
int vakitleriCikar(QJsonValue value);
PrayerTimesParser();
int vakitleriCikar(QJsonValue value);
};

#endif // PRAYERTIMESPARSER_H
5 changes: 5 additions & 0 deletions updatecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ void UpdateController::isNewVersionAvailable()
// {
// return;
// }

if (QMessageBox(QMessageBox::Question, "Namaz Vakti Hatırlatıcı", "Yeni sürüm bulundu\nİndirilelim mi?", QMessageBox::No|QMessageBox::Yes).exec() == QMessageBox::No)
{
return;
}
// fetchTimes.downloadSynchronous("", "https://github.com/atakli/PrayerReminder-Desktop/releases/latest/download/PrayerReminder.zip");
fetchTimes.downloadSynchronous("", loadDoc["assets"][0]["browser_download_url"].toString()); // ismi PrayerReminder.zip'dan başka bişey olursa diye
break;
Expand Down
1 change: 1 addition & 0 deletions updatecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <QWidget>
#include <QObject>
#include <QDialog>

class UpdateController : public QObject
{
Expand Down
20 changes: 14 additions & 6 deletions window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "window.h"
#include "calcTimes.h"
#include "prayertimesparser.h"
#include "ui_sehirSecwindow.h"

#ifndef QT_NO_SYSTEMTRAYICON
Expand Down Expand Up @@ -119,14 +118,20 @@ void Window::showMessage()

void Window::createActions()
{
quitAction = new QAction(tr("&Quit"), this);
quitAction = new QAction(tr("&Çıkış"), this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
sehirSecimiAction = new QAction(tr("&Şehir seç"), this);
updateAction = new QAction(tr("&Yeni sürüm var mı?"), this);
emailAction = new QAction(tr("&Önerini Yaz"), this);
// connect(sehirSecimiAction, &QAction::triggered, this, &Window::bolgeSec);
connect(sehirSecimiAction, SIGNAL(triggered()), this, SLOT(bolgeSec())); // sanırım this'i kaldırınca da aynı mana
connect(updateAction, SIGNAL(triggered()), this, SLOT(controlUpdate()));
connect(this, &Window::son5Dk, this, &Window::showMessage);
}

void Window::controlUpdate()
{
update.isNewVersionAvailable();
}
void Window::ilkBolgeSecimi()
{
ui->sehir->setCurrentText("KOCAELİ");
Expand Down Expand Up @@ -170,6 +175,8 @@ void Window::executeIlceKodu(int ilceIndex)
void Window::downloadEvkat()
{
QString urlSpec = "https://ezanvakti.herokuapp.com/vakitler/" + ilceKodu; // note that times in this site are not updated everyday
CalcTimes calc;
calc.offlineVakitleriHesapla();
QString fileName = applicationDirPath + evkatOnlinePath;
// fileName = applicationDirPath + "/releases.html";
// urlSpec = "https://github.com/atakli/PrayerReminder-Desktop/releases/";
Expand Down Expand Up @@ -197,17 +204,18 @@ void Window::bolgeSec()
void Window::createTrayIcon()
{
trayIconMenu = new QMenu(this);
// trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIconMenu->addAction(sehirSecimiAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(updateAction);
// trayIconMenu->addAction(emailAction);
trayIconMenu->addAction(quitAction);

trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}

void Window::showTime()
{
PrayerTimesParser ptp; // TODO: her saniye burdaki her işi yapmasına gerek yok aslında, sanırım
int kalanVakit = ptp.nextDay();
if(kalanVakit <= 60) // 60 dk'dan az kalmadıysa gösterme. bi de zaten ikiden fazla basamak göstermeye uygun değil ve gerek de yok
{
Expand Down
7 changes: 6 additions & 1 deletion window.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QDialog>
#include <QWidget>

#include "prayertimesparser.h"
#include "updatecontroller.h"
#include "fetchtimes.h"

Expand All @@ -36,6 +37,7 @@ private slots:
void fillCities(int ulkeIndex);
void fillTown(int sehirIndex);
void executeIlceKodu(int ilceIndex);
void controlUpdate();
public slots:
void showMessage();

Expand All @@ -48,6 +50,7 @@ public slots:
QString ulkeFile, sehirFile, ilceFile;
QString ulkeKodu, sehirKodu, ilceKodu;
void controlOnlineEvkatFileExistOtherwiseRequestDownload();
PrayerTimesParser ptp;
UpdateController update;
bool compareTagVersion(QString tag, QString currentTag);
HttpWindow fetchTimes; // TODO: önceki hali gibi olup da signal slot ile filan HttpWindow'dan Window'a sinyal gönderip indirme işlemi bitmeden fetchTimes objesinin ömrünü doldurmasını
Expand All @@ -61,7 +64,9 @@ public slots:

QElapsedTimer timer;

QAction *quitAction;
QAction *emailAction;
QAction *quitAction;
QAction *updateAction;
QAction *sehirSecimiAction;

QSystemTrayIcon *trayIcon;
Expand Down

0 comments on commit 1c0f1fb

Please sign in to comment.