From 247c5476301dea2715ea6d90758d7b182400c732 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 9 Sep 2014 15:45:44 +0200 Subject: [PATCH] Refactorings. --- src/core/feedsmodelcategory.cpp | 3 +-- src/core/feedsmodelfeed.cpp | 8 ++------ src/gui/feedsview.cpp | 7 +++++-- src/gui/formupdate.cpp | 10 ++-------- src/main.cpp | 7 ++----- src/miscellaneous/application.h | 16 ++++++++++++++++ src/miscellaneous/databasefactory.cpp | 3 --- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index 80098bb51..0a3248880 100755 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -130,8 +130,7 @@ bool FeedsModelCategory::removeItself() { } // Children are removed, remove this standard category too. - QSqlDatabase database = qApp->database()->connection("FeedsModelCategory", - DatabaseFactory::FromSettings); + QSqlDatabase database = qApp->database()->connection("FeedsModelCategory", DatabaseFactory::FromSettings); QSqlQuery query_remove(database); query_remove.setForwardOnly(true); diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index 8df124944..0e875c252 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -392,9 +392,7 @@ QVariant FeedsModelFeed::data(int column, int role) const { void FeedsModelFeed::update() { QByteArray feed_contents; int download_timeout = qApp->settings()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(); - m_networkError = NetworkFactory::downloadFile(url(), download_timeout, - feed_contents, passwordProtected(), - username(), password()); + m_networkError = NetworkFactory::downloadFile(url(), download_timeout, feed_contents, passwordProtected(), username(), password()); if (m_networkError != QNetworkReply::NoError) { qWarning("Error during fetching of new messages for feed '%s' (id %d).", qPrintable(url()), id()); @@ -524,9 +522,7 @@ void FeedsModelFeed::updateMessages(const QList &messages) { query_select.finish(); - if (datetime_stamps.size() == 0 || - (message.m_createdFromFeed && - !datetime_stamps.contains(message.m_created.toMSecsSinceEpoch()))) { + if (datetime_stamps.isEmpty() ||(message.m_createdFromFeed && !datetime_stamps.contains(message.m_created.toMSecsSinceEpoch()))) { // Message is not fetched in this feed yet // or it is. If it is, then go // through datetime stamps of stored messages diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index a0e7c34b0..7319dbd2d 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -351,8 +351,8 @@ void FeedsView::deleteSelectedItem() { selection_model->clearSelection(); selection_model->select(current_index, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); - qApp->showGuiMessage(tr("Cannot delete item"), - tr("Selected item cannot be deleted because feed update is ongoing."), + qApp->showGuiMessage(tr("You selected multiplet items for deletion."), + tr("You can delete feeds/categories only one by one."), QSystemTrayIcon::Warning, qApp->mainForm()); } @@ -365,6 +365,9 @@ void FeedsView::deleteSelectedItem() { else { // Item WAS NOT removed, either database-related error occurred // or update is undergoing. + qApp->showGuiMessage(tr("Deletion of item failed."), + tr("Selected item was not deleted due to error."), + QSystemTrayIcon::Warning, qApp->mainForm()); } // Changes are done, unlock the update master lock. diff --git a/src/gui/formupdate.cpp b/src/gui/formupdate.cpp index bf8753e83..24f779e2d 100755 --- a/src/gui/formupdate.cpp +++ b/src/gui/formupdate.cpp @@ -28,7 +28,6 @@ #include "gui/systemtrayicon.h" #include -#include #include #if defined(Q_OS_WIN) @@ -94,7 +93,7 @@ void FormUpdate::checkForUpdates() { bool is_self_update_for_this_system = isUpdateForThisSystem() && isSelfUpdateSupported(); - if (update.first.m_availableVersion > APP_VERSION) { + if (update.first.m_availableVersion != APP_VERSION) { m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok, tr("New release available."), tr("This is new version which can be\ndownloaded and installed.")); @@ -130,12 +129,7 @@ void FormUpdate::updateProgress(qint64 bytes_received, qint64 bytes_total) { void FormUpdate::saveUpdateFile(const QByteArray &file_contents) { QString url_file = m_updateInfo.m_urls.value(OS_ID).m_fileUrl;; - -#if QT_VERSION >= 0x050000 - QString temp_directory = QStandardPaths::writableLocation(QStandardPaths::TempLocation); -#else - QString temp_directory = QDesktopServices::storageLocation(QDesktopServices::TempLocation); -#endif + QString temp_directory = qApp->getTempDirectory(); if (!temp_directory.isEmpty()) { QString output_file_name = url_file.mid(url_file.lastIndexOf('/') + 1); diff --git a/src/main.cpp b/src/main.cpp index 78e0c2673..381937f26 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,8 +87,7 @@ int main(int argc, char *argv[]) { Application::setOrganizationDomain(APP_URL); Application::setWindowIcon(QIcon(APP_ICON_PATH)); - qDebug().nospace() << "Creating main application form in thread: \'" << - QThread::currentThreadId() << "\'."; + qDebug().nospace() << "Creating main application form in thread: \'" << QThread::currentThreadId() << "\'."; // Instantiate main application window. FormMain main_window; @@ -100,9 +99,7 @@ int main(int argc, char *argv[]) { DynamicShortcuts::load(main_window.allActions()); // Display main window. - if (qApp->settings()->value(APP_CFG_GUI, "start_hidden", - false).toBool() && - SystemTrayIcon::isSystemTrayActivated()) { + if (qApp->settings()->value(APP_CFG_GUI, "start_hidden", false).toBool() && SystemTrayIcon::isSystemTrayActivated()) { qDebug("Hiding the main window when the application is starting."); main_window.switchVisibility(true); } diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h index 41ae6bf53..aac70f744 100755 --- a/src/miscellaneous/application.h +++ b/src/miscellaneous/application.h @@ -31,6 +31,12 @@ #include #include +#if QT_VERSION >= 0x050000 +#include +#else +#include +#endif + #if defined(qApp) #undef qApp #endif @@ -113,6 +119,16 @@ class Application : public QtSingleApplication { m_mainForm = main_form; } + inline QString getTempDirectory() { +#if QT_VERSION >= 0x050000 + QString temp_directory = QStandardPaths::writableLocation(QStandardPaths::TempLocation); +#else + QString temp_directory = QDesktopServices::storageLocation(QDesktopServices::TempLocation); +#endif + + return temp_directory; + } + // Access to application tray icon. Always use this in cooperation with // SystemTrayIcon::isSystemTrayActivated(). SystemTrayIcon *trayIcon(); diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp index e0a1b740c..5f1d7a062 100755 --- a/src/miscellaneous/databasefactory.cpp +++ b/src/miscellaneous/databasefactory.cpp @@ -50,15 +50,12 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString & if (database.open()) { // Connection succeeded, clean up the mess and return OK status. database.close(); - removeConnection(APP_DB_MYSQL_TEST); return MySQLOk; } else { // Connection failed, do cleanup and return specific // error code. MySQLError error_code = static_cast(database.lastError().number()); - - removeConnection(APP_DB_MYSQL_TEST); return error_code; } }