Refactorings...

This commit is contained in:
Martin Rotter 2014-07-26 22:29:29 +02:00
parent 7aa22a5fd5
commit 7da1338552
5 changed files with 48 additions and 142 deletions

View File

@ -18,7 +18,6 @@
#include "application.h"
#include "miscellaneous/systemfactory.h"
#include "gui/formmain.h"
#include "gui/feedsview.h"
#include "gui/feedmessageviewer.h"
#include "gui/messagebox.h"

View File

@ -23,6 +23,7 @@
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "gui/systemtrayicon.h"
#include "gui/formmain.h"
#include <QMutex>
@ -33,7 +34,6 @@
// Define new qApp macro. Yeaaaaah.
#define qApp (Application::instance())
class FormMain;
// TODO: presunout nektery veci sem, settings atp
class Application : public QtSingleApplication {

View File

@ -382,46 +382,28 @@ void FeedMessageViewer::initializeViews() {
}
void FeedMessageViewer::vacuumDatabase() {
bool is_tray_activated = SystemTrayIcon::isSystemTrayActivated();
if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (is_tray_activated) {
qApp->trayIcon()->showMessage(tr("Cannot defragment database"),
tr("Database cannot be defragmented because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot defragment database"),
tr("Database cannot be defragmented because feed update is ongoing."));
}
// Thus, cannot delete and quit the method.
qApp->showGuiMessage(tr("Cannot defragment database"),
tr("Database cannot be defragmented because feed update is ongoing."),
QSystemTrayIcon::Warning,
this);
return;
}
if (DatabaseFactory::instance()->vacuumDatabase()) {
qApp->showGuiMessage(tr("Database defragmented"),
tr("Database was successfully defragmented."),
QSystemTrayIcon::Information);
QSystemTrayIcon::Information,
this);
}
else {
if (is_tray_activated) {
qApp->trayIcon()->showMessage(tr("Database was not defragmented"),
tr("Database was not defragmented. This database backend does not support it or it cannot be defragmented now."),
QSystemTrayIcon::Warning,
TRAY_ICON_BUBBLE_TIMEOUT);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Database was not defragmented"),
tr("Database was not defragmented. This database backend does not support it or it cannot be defragmented now."));
}
qApp->showGuiMessage(tr("Database was not defragmented"),
tr("Database was not defragmented. This database backend does not support it or it cannot be defragmented now."),
QSystemTrayIcon::Warning,
this);
}
qApp->closeLock()->unlock();

View File

@ -144,17 +144,9 @@ void FeedsView::updateAllFeeds() {
emit feedsUpdateRequested(allFeeds());
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot update all items"),
tr("You cannot update all items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot update all items"),
tr("You cannot update all items because another feed update is ongoing."));
}
qApp->showGuiMessage(tr("Cannot update all items"),
tr("You cannot update all items because another feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
}
}
@ -170,17 +162,9 @@ void FeedsView::updateSelectedFeeds() {
emit feedsUpdateRequested(selectedFeeds());
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot update selected items"),
tr("You cannot update selected items because another feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot update selected items"),
tr("You cannot update selected items because another feed update is ongoing."));
}
qApp->showGuiMessage(tr("Cannot update selected items"),
tr("You cannot update selected items because another feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
}
}
@ -196,8 +180,7 @@ void FeedsView::executeNextAutoUpdate() {
// If global auto-update is enabled
// and its interval counter reached zero,
// then we need to restore it.
if (m_globalAutoUpdateEnabled &&
--m_globalAutoUpdateRemainingInterval < 0) {
if (m_globalAutoUpdateEnabled && --m_globalAutoUpdateRemainingInterval < 0) {
// We should start next auto-update interval.
m_globalAutoUpdateRemainingInterval = m_globalAutoUpdateInitialInterval;
}
@ -218,12 +201,8 @@ void FeedsView::executeNextAutoUpdate() {
// Request update for given feeds.
emit feedsUpdateRequested(feeds_for_update);
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Scheduled update started"),
//: RSS Guard is performing updates right now.
tr("%1 is performing scheduled update of some feeds.").arg(APP_NAME),
QSystemTrayIcon::Information);
}
// NOTE: OSD/bubble informing about performing
// of scheduled update can be shown now.
}
}
@ -254,19 +233,9 @@ void FeedsView::addNewCategory() {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot add standard category"),
tr("You cannot add new standard category now because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot add standard category"),
tr("You cannot add new standard category now because feed update is ongoing."));
}
// Thus, cannot delete and quit the method.
qApp->showGuiMessage(tr("Cannot add standard category"),
tr("You cannot add new standard category now because feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
return;
}
@ -293,19 +262,9 @@ void FeedsView::addNewFeed() {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because feed update is ongoing."));
}
// Thus, cannot delete and quit the method.
qApp->showGuiMessage(tr("Cannot add standard feed"),
tr("You cannot add new standard feed now because feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
return;
}
@ -332,19 +291,9 @@ void FeedsView::editSelectedItem() {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
//: Warning messagebox title when selected item cannot be edited.
qApp->trayIcon()->showMessage(tr("Cannot edit item"),
tr("Selected item cannot be edited because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
//: Warning messagebox title when selected item cannot be edited.
tr("Cannot edit item"),
tr("Selected item cannot be edited because feed update is ongoing."));
}
qApp->showGuiMessage(tr("Cannot edit item"),
tr("Selected item cannot be edited because feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
// Thus, cannot delete and quit the method.
return;
@ -382,17 +331,9 @@ void FeedsView::deleteSelectedItem() {
// Lock was not obtained because
// it is used probably by feed updater or application
// is quitting.
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
else {
MessageBox::show(this,
QMessageBox::Warning,
tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."));
}
qApp->showGuiMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
// Thus, cannot delete and quit the method.
return;
@ -411,11 +352,9 @@ void FeedsView::deleteSelectedItem() {
selection_model->clearSelection();
selection_model->select(current_index, QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent);
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning);
}
qApp->showGuiMessage(tr("Cannot delete item"),
tr("Selected item cannot be deleted because feed update is ongoing."),
QSystemTrayIcon::Warning, qApp->mainForm());
}
if (m_sourceModel->removeItem(m_proxyModel->mapToSource(current_index))) {

View File

@ -38,7 +38,7 @@
FormCategoryDetails::FormCategoryDetails(FeedsModel *model,
QWidget *parent)
QWidget *parent)
: QDialog(parent),
m_editableCategory(NULL),
m_feedsModel(model) {
@ -118,17 +118,10 @@ void FormCategoryDetails::apply() {
accept();
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot add category"),
tr("Category was not added due to error."),
QSystemTrayIcon::Critical);
}
else {
MessageBox::show(this,
QMessageBox::Critical,
tr("Cannot add category"),
tr("Category was not added due to error."));
}
qApp->showGuiMessage(tr("Cannot add category"),
tr("Category was not added due to error."),
QSystemTrayIcon::Critical,
qApp->mainForm());
}
}
else {
@ -136,17 +129,10 @@ void FormCategoryDetails::apply() {
accept();
}
else {
if (SystemTrayIcon::isSystemTrayActivated()) {
qApp->trayIcon()->showMessage(tr("Cannot edit category"),
tr("Category was not edited due to error."),
QSystemTrayIcon::Critical);
}
else {
MessageBox::show(this,
QMessageBox::Critical,
tr("Cannot edit category"),
tr("Category was not edited due to error."));
}
qApp->showGuiMessage(tr("Cannot edit category"),
tr("Category was not edited due to error."),
QSystemTrayIcon::Critical,
qApp->mainForm());
}
}
}
@ -154,11 +140,11 @@ void FormCategoryDetails::apply() {
void FormCategoryDetails::onTitleChanged(const QString &new_title){
if (new_title.simplified().size() >= MIN_CATEGORY_NAME_LENGTH) {
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Ok, tr("Category name is ok."));
m_ui->m_txtTitle->setStatus(WidgetWithStatus::Ok, tr("Category name is ok."));
}
else {
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
m_ui->m_txtTitle->setStatus(LineEditWithStatus::Error, tr("Category name is too short."));
m_ui->m_txtTitle->setStatus(WidgetWithStatus::Error, tr("Category name is too short."));
}
}
@ -246,8 +232,8 @@ void FormCategoryDetails::initialize() {
}
void FormCategoryDetails::loadCategories(const QList<FeedsModelCategory*> categories,
FeedsModelRootItem *root_item,
FeedsModelCategory *input_category) {
FeedsModelRootItem *root_item,
FeedsModelCategory *input_category) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));