Refactorings...

This commit is contained in:
Martin Rotter 2014-01-13 21:43:35 +01:00
parent 5667b905b8
commit 406cc9cde5
20 changed files with 88 additions and 102 deletions

View file

@ -366,11 +366,6 @@ set(APP_FORMS
src/gui/formcategorydetails.ui src/gui/formcategorydetails.ui
) )
# Add resources.
set(APP_RESOURCES
resources/rssguard_resources.qrc
)
# Add translations. # Add translations.
set(APP_TRANSLATIONS set(APP_TRANSLATIONS
localization/rssguard_en.ts localization/rssguard_en.ts
@ -397,7 +392,6 @@ set(APP_TEXT
# Wrap files, create moc files. # Wrap files, create moc files.
if(${USE_QT_5}) if(${USE_QT_5})
qt5_wrap_ui(APP_UI ${APP_FORMS}) qt5_wrap_ui(APP_UI ${APP_FORMS})
qt5_add_resources(APP_RCC ${APP_RESOURCES})
# Load translations. # Load translations.
if(Qt5LinguistTools_FOUND) if(Qt5LinguistTools_FOUND)
@ -409,7 +403,6 @@ if(${USE_QT_5})
else(${USE_QT_5}) else(${USE_QT_5})
qt4_wrap_cpp(APP_MOC ${APP_HEADERS}) qt4_wrap_cpp(APP_MOC ${APP_HEADERS})
qt4_wrap_ui(APP_UI ${APP_FORMS}) qt4_wrap_ui(APP_UI ${APP_FORMS})
qt4_add_resources(APP_RCC ${APP_RESOURCES})
# Load translations. # Load translations.
qt4_add_translation(APP_QM ${APP_TRANSLATIONS}) qt4_add_translation(APP_QM ${APP_TRANSLATIONS})

View file

@ -1 +0,0 @@
<RCC/>

View file

@ -34,12 +34,12 @@ DatabaseFactory *DatabaseFactory::instance() {
void DatabaseFactory::assemblyDatabaseFilePath() { void DatabaseFactory::assemblyDatabaseFilePath() {
if (Settings::instance()->type() == Settings::Portable) { if (Settings::instance()->type() == Settings::Portable) {
m_databasePath = qApp->applicationDirPath() + m_databaseFilePath = qApp->applicationDirPath() +
QDir::separator() + QDir::separator() +
QString(APP_DB_PATH); QString(APP_DB_PATH);
} }
else { else {
m_databasePath = QDir::homePath() + QDir::separator() + m_databaseFilePath = QDir::homePath() + QDir::separator() +
QString(APP_LOW_H_NAME) + QDir::separator() + QString(APP_LOW_H_NAME) + QDir::separator() +
QString(APP_DB_PATH); QString(APP_DB_PATH);
} }
@ -298,11 +298,6 @@ QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
} }
} }
void DatabaseFactory::removeConnection(const QString &connection_name) {
qDebug("Removing database connection '%s'.", qPrintable(connection_name));
QSqlDatabase::removeDatabase(connection_name);
}
void DatabaseFactory::saveMemoryDatabase() { void DatabaseFactory::saveMemoryDatabase() {
QSqlDatabase database = connection(); QSqlDatabase database = connection();
QSqlDatabase file_database = connection(objectName(), false); QSqlDatabase file_database = connection(objectName(), false);

View file

@ -15,7 +15,7 @@ class DatabaseFactory : public QObject {
// Returns absolute file path to database file. // Returns absolute file path to database file.
inline QString getDatabasePath() { inline QString getDatabasePath() {
return m_databasePath; return m_databaseFilePath;
} }
// If in-memory is true, then :memory: database is returned // If in-memory is true, then :memory: database is returned
@ -25,7 +25,11 @@ class DatabaseFactory : public QObject {
bool in_memory = true); bool in_memory = true);
// Removes connection. // Removes connection.
void removeConnection(const QString &connection_name = QString()); inline void removeConnection(const QString &connection_name = QString()) {
qDebug("Removing database connection '%s'.", qPrintable(connection_name));
QSqlDatabase::removeDatabase(connection_name);
}
// Performs saving of items from in-memory database // Performs saving of items from in-memory database
// to file-based database. // to file-based database.
@ -47,7 +51,7 @@ class DatabaseFactory : public QObject {
QSqlDatabase initializeFileBasedDatabase(const QString &connection_name); QSqlDatabase initializeFileBasedDatabase(const QString &connection_name);
// Path to database file. // Path to database file.
QString m_databasePath; QString m_databaseFilePath;
// Is database file initialized? // Is database file initialized?
bool m_fileBasedinitialized; bool m_fileBasedinitialized;

View file

@ -38,10 +38,6 @@ FeedsModel::~FeedsModel() {
delete m_rootItem; delete m_rootItem;
} }
QVariant FeedsModel::data(const QModelIndex &index, int role) const {
return itemForIndex(index)->data(index.column(), role);
}
QVariant FeedsModel::headerData(int section, QVariant FeedsModel::headerData(int section,
Qt::Orientation orientation, Qt::Orientation orientation,
int role) const { int role) const {
@ -137,14 +133,6 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
return parent_item->childCount(); return parent_item->childCount();
} }
int FeedsModel::countOfAllMessages() const {
return m_rootItem->countOfAllMessages();
}
int FeedsModel::countOfUnreadMessages() const {
return m_rootItem->countOfUnreadMessages();
}
// TODO: přepsat tudle metodu, // TODO: přepsat tudle metodu,
// vim ze to zhruba funguje ale je potreba pridat taky // vim ze to zhruba funguje ale je potreba pridat taky
// vymazani feedu/kategorie z SQL (pridat metodu do FeedsModelRootItem // vymazani feedu/kategorie z SQL (pridat metodu do FeedsModelRootItem
@ -600,10 +588,6 @@ void FeedsModel::assembleFeeds(FeedAssignment feeds) {
} }
} }
FeedsModelRootItem *FeedsModel::rootItem() const {
return m_rootItem;
}
void FeedsModel::assembleCategories(CategoryAssignment categories) { void FeedsModel::assembleCategories(CategoryAssignment categories) {
QHash<int, FeedsModelRootItem*> assignments; QHash<int, FeedsModelRootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, m_rootItem); assignments.insert(NO_PARENT_CATEGORY, m_rootItem);

View file

@ -4,11 +4,11 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include "core/messagesmodel.h" #include "core/messagesmodel.h"
#include "core/feedsmodelrootitem.h"
#include <QIcon> #include <QIcon>
class FeedsModelRootItem;
class FeedsModelCategory; class FeedsModelCategory;
class FeedsModelFeed; class FeedsModelFeed;
@ -26,7 +26,10 @@ class FeedsModel : public QAbstractItemModel {
virtual ~FeedsModel(); virtual ~FeedsModel();
// Model implementation. // Model implementation.
QVariant data(const QModelIndex &index, int role) const; inline QVariant data(const QModelIndex &index, int role) const {
return itemForIndex(index)->data(index.column(), role);
}
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const;
@ -34,8 +37,13 @@ class FeedsModel : public QAbstractItemModel {
int rowCount(const QModelIndex &parent) const; int rowCount(const QModelIndex &parent) const;
// Returns couns of ALL/UNREAD (non-deleted) messages for the model. // Returns couns of ALL/UNREAD (non-deleted) messages for the model.
int countOfAllMessages() const; inline int countOfAllMessages() const {
int countOfUnreadMessages() const; return m_rootItem->countOfAllMessages();
}
inline int countOfUnreadMessages() const {
return m_rootItem->countOfUnreadMessages();
}
// Feed/category manipulators. // Feed/category manipulators.
bool removeItems(const QModelIndexList &indexes); bool removeItems(const QModelIndexList &indexes);
@ -84,7 +92,9 @@ class FeedsModel : public QAbstractItemModel {
QModelIndex indexForItem(FeedsModelRootItem *item) const; QModelIndex indexForItem(FeedsModelRootItem *item) const;
// Access to root item. // Access to root item.
FeedsModelRootItem *rootItem() const; inline FeedsModelRootItem *rootItem() const {
return m_rootItem;
}
public slots: public slots:
// Feeds operations. // Feeds operations.

View file

@ -24,11 +24,3 @@ FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other)
FeedsModelCategory::~FeedsModelCategory() { FeedsModelCategory::~FeedsModelCategory() {
} }
FeedsModelCategory:: Type FeedsModelCategory::type() const {
return m_type;
}
void FeedsModelCategory::setType(const Type &type) {
m_type = type;
}

View file

@ -25,8 +25,13 @@ class FeedsModelCategory : public FeedsModelRootItem {
virtual ~FeedsModelCategory(); virtual ~FeedsModelCategory();
// All types of categories offer these getters/setters. // All types of categories offer these getters/setters.
Type type() const; inline Type type() const {
void setType(const Type &type); return m_type;
}
inline void setType(const Type &type) {
m_type = type;
}
protected: protected:
Type m_type; Type m_type;

View file

@ -29,17 +29,6 @@ int FeedsModelFeed::countOfUnreadMessages() const {
return m_unreadCount; return m_unreadCount;
} }
void FeedsModelFeed::update() {
}
FeedsModelFeed::Type FeedsModelFeed::type() const {
return m_type;
}
void FeedsModelFeed::setType(const Type &type) {
m_type = type;
}
QString FeedsModelFeed::typeToString(FeedsModelFeed::Type type) { QString FeedsModelFeed::typeToString(FeedsModelFeed::Type type) {
switch (type) { switch (type) {
case StandardAtom10: case StandardAtom10:

View file

@ -34,11 +34,17 @@ class FeedsModelFeed : public FeedsModelRootItem {
// NOTE: This method is used in the "update worker". // NOTE: This method is used in the "update worker".
// For example, it can fetch new messages from a remote destination // For example, it can fetch new messages from a remote destination
// and store them in a local database and so on. // and store them in a local database and so on.
virtual void update(); virtual void update() {
}
// Other getters/setters. // Other getters/setters.
Type type() const; inline Type type() const {
void setType(const Type &type); return m_type;
}
inline void setType(const Type &type) {
m_type = type;
}
// Converts particular feed type to string. // Converts particular feed type to string.
static QString typeToString(Type type); static QString typeToString(Type type);

View file

@ -12,17 +12,10 @@ FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
FeedsModelRootItem::~FeedsModelRootItem() { FeedsModelRootItem::~FeedsModelRootItem() {
qDebug("Destroying FeedsModelRootItem instance."); qDebug("Destroying FeedsModelRootItem instance.");
qDeleteAll(m_childItems); qDeleteAll(m_childItems);
} }
FeedsModelRootItem *FeedsModelRootItem::parent() const {
return m_parentItem;
}
void FeedsModelRootItem::setParent(FeedsModelRootItem *parent_item) {
m_parentItem = parent_item;
}
FeedsModelRootItem::Kind FeedsModelRootItem::kind() const { FeedsModelRootItem::Kind FeedsModelRootItem::kind() const {
return m_kind; return m_kind;
} }
@ -31,10 +24,6 @@ QIcon FeedsModelRootItem::icon() const {
return m_icon; return m_icon;
} }
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
return m_childItems.value(row);
}
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) { void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
m_childItems.append(child); m_childItems.append(child);
child->setParent(this); child->setParent(this);

View file

@ -23,9 +23,18 @@ class FeedsModelRootItem {
virtual ~FeedsModelRootItem(); virtual ~FeedsModelRootItem();
// Basic operations. // Basic operations.
virtual FeedsModelRootItem *parent() const; inline virtual FeedsModelRootItem *parent() const {
virtual void setParent(FeedsModelRootItem *parent_item); return m_parentItem;
virtual FeedsModelRootItem *child(int row); }
inline virtual void setParent(FeedsModelRootItem *parent_item) {
m_parentItem = parent_item;
}
inline virtual FeedsModelRootItem *child(int row) {
return m_childItems.value(row);
}
virtual void appendChild(FeedsModelRootItem *child); virtual void appendChild(FeedsModelRootItem *child);
virtual int childCount() const; virtual int childCount() const;
virtual int columnCount() const; virtual int columnCount() const;

View file

@ -28,6 +28,11 @@ class FeedMessageViewer : public TabContent {
return m_messagesBrowser; return m_messagesBrowser;
} }
// FeedsView getter.
inline FeedsView *feedsView() {
return m_feedsView;
}
// Loads/saves sizes and states of ALL // Loads/saves sizes and states of ALL
// underlying widgets, this contains primarily // underlying widgets, this contains primarily
// splitters, toolbar and views. // splitters, toolbar and views.

View file

@ -82,7 +82,7 @@ class FeedsView : public QTreeView {
// Notifies other components about messages // Notifies other components about messages
// counts. // counts.
void notifyWithCounts() { inline void notifyWithCounts() {
emit feedCountsChanged(m_sourceModel->countOfUnreadMessages(), emit feedCountsChanged(m_sourceModel->countOfUnreadMessages(),
m_sourceModel->countOfAllMessages()); m_sourceModel->countOfAllMessages());
} }

View file

@ -56,15 +56,15 @@ FormMain *FormMain::instance() {
return s_instance; return s_instance;
} }
QMenu *FormMain::getTrayMenu() { QMenu *FormMain::trayMenu() {
return m_trayMenu; return m_trayMenu;
} }
TabWidget *FormMain::getTabWidget() { TabWidget *FormMain::tabWidget() {
return m_ui->m_tabWidget; return m_ui->m_tabWidget;
} }
QList<QAction*> FormMain::getActions() { QList<QAction*> FormMain::allActions() {
QList<QAction*> actions; QList<QAction*> actions;
// Add basic actions. // Add basic actions.
@ -358,10 +358,7 @@ void FormMain::showAbout() {
void FormMain::showSettings() { void FormMain::showSettings() {
QPointer<FormSettings> form_pointer = new FormSettings(this); QPointer<FormSettings> form_pointer = new FormSettings(this);
if (form_pointer.data()->exec() == QDialog::Accepted) { form_pointer.data()->exec();
// User applied new settings, reload neede components.
m_ui->m_tabWidget->checkTabBarVisibility();
}
delete form_pointer.data(); delete form_pointer.data();
} }

View file

@ -23,14 +23,15 @@ class FormMain : public QMainWindow {
virtual ~FormMain(); virtual ~FormMain();
// Returns menu for the tray icon. // Returns menu for the tray icon.
QMenu *getTrayMenu(); QMenu *trayMenu();
// Returns global tab widget. // Returns global tab widget.
TabWidget *getTabWidget(); TabWidget *tabWidget();
// Returns list of all globally available actions. // Returns list of all globally available actions.
// NOTE: This is used for setting dynamic shortcuts for given actions. // NOTE: This is used for setting dynamic shortcuts
QList<QAction*> getActions(); // for given actions.
QList<QAction*> allActions();
// Access to statusbar. // Access to statusbar.
StatusBar *statusBar(); StatusBar *statusBar();
@ -73,6 +74,7 @@ class FormMain : public QMainWindow {
void switchFullscreenMode(bool turn_fullscreen_on); void switchFullscreenMode(bool turn_fullscreen_on);
protected slots: protected slots:
// Last-minute reactors.
void onCommitData(QSessionManager &manager); void onCommitData(QSessionManager &manager);
void onSaveState(QSessionManager &manager); void onSaveState(QSessionManager &manager);
@ -87,7 +89,6 @@ class FormMain : public QMainWindow {
void showAbout(); void showAbout();
private: private:
bool m_quitting;
Ui::FormMain *m_ui; Ui::FormMain *m_ui;
QMenu *m_trayMenu; QMenu *m_trayMenu;
StatusBar *m_statusBar; StatusBar *m_statusBar;

View file

@ -11,6 +11,8 @@
#include "gui/iconthemefactory.h" #include "gui/iconthemefactory.h"
#include "gui/skinfactory.h" #include "gui/skinfactory.h"
#include "gui/systemtrayicon.h" #include "gui/systemtrayicon.h"
#include "gui/feedmessageviewer.h"
#include "gui/feedsview.h"
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/webbrowser.h" #include "gui/webbrowser.h"
@ -408,7 +410,7 @@ void FormSettings::saveLanguage() {
} }
void FormSettings::loadShortcuts() { void FormSettings::loadShortcuts() {
m_ui->m_shortcuts->populate(FormMain::instance()->getActions()); m_ui->m_shortcuts->populate(FormMain::instance()->allActions());
} }
void FormSettings::saveShortcuts() { void FormSettings::saveShortcuts() {
@ -416,7 +418,7 @@ void FormSettings::saveShortcuts() {
m_ui->m_shortcuts->updateShortcuts(); m_ui->m_shortcuts->updateShortcuts();
// Save new shortcuts to the settings. // Save new shortcuts to the settings.
DynamicShortcuts::save(FormMain::instance()->getActions()); DynamicShortcuts::save(FormMain::instance()->allActions());
} }
void FormSettings::loadGeneral() { void FormSettings::loadGeneral() {
@ -551,6 +553,7 @@ void FormSettings::saveInterface() {
m_ui->m_checkHidden->isChecked()); m_ui->m_checkHidden->isChecked());
if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) { if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
SystemTrayIcon::instance()->show(); SystemTrayIcon::instance()->show();
FormMain::instance()->tabWidget()->feedMessageViewer()->feedsView()->notifyWithCounts();
} }
else { else {
FormMain::instance()->display(); FormMain::instance()->display();
@ -587,4 +590,6 @@ void FormSettings::saveInterface() {
m_ui->m_checkNewTabDoubleClick->isChecked()); m_ui->m_checkNewTabDoubleClick->isChecked());
settings->setValue(APP_CFG_GUI, "hide_tabbar_one_tab", settings->setValue(APP_CFG_GUI, "hide_tabbar_one_tab",
m_ui->m_hideTabBarIfOneTabVisible->isChecked()); m_ui->m_hideTabBarIfOneTabVisible->isChecked());
FormMain::instance()->tabWidget()->checkTabBarVisibility();
} }

View file

@ -46,7 +46,7 @@ SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
// Initialize icon. // Initialize icon.
setNumber(); setNumber();
setContextMenu(parent->getTrayMenu()); setContextMenu(parent->trayMenu());
// Create necessary connections. // Create necessary connections.
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),

View file

@ -122,7 +122,7 @@ void WebBrowser::createConnections() {
connect(m_webView, SIGNAL(urlChanged(QUrl)), this, SLOT(updateUrl(QUrl))); connect(m_webView, SIGNAL(urlChanged(QUrl)), this, SLOT(updateUrl(QUrl)));
// Connect this WebBrowser to global TabWidget. // Connect this WebBrowser to global TabWidget.
TabWidget *tab_widget = FormMain::instance()->getTabWidget(); TabWidget *tab_widget = FormMain::instance()->tabWidget();
connect(m_webView, SIGNAL(newTabRequested()), tab_widget, SLOT(addEmptyBrowser())); connect(m_webView, SIGNAL(newTabRequested()), tab_widget, SLOT(addEmptyBrowser()));
connect(m_webView, SIGNAL(linkMiddleClicked(QUrl)), connect(m_webView, SIGNAL(linkMiddleClicked(QUrl)),
tab_widget, SLOT(addLinkedBrowser(QUrl))); tab_widget, SLOT(addLinkedBrowser(QUrl)));

View file

@ -9,6 +9,8 @@
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/formwelcome.h" #include "gui/formwelcome.h"
#include "gui/systemtrayicon.h" #include "gui/systemtrayicon.h"
#include "gui/feedmessageviewer.h"
#include "gui/feedsview.h"
#include "qtsingleapplication/qtsingleapplication.h" #include "qtsingleapplication/qtsingleapplication.h"
// Needed for setting ini file format on Mac OS. // Needed for setting ini file format on Mac OS.
@ -83,18 +85,18 @@ int main(int argc, char *argv[]) {
QThread::currentThreadId() << "\'."; QThread::currentThreadId() << "\'.";
// Instantiate main application window. // Instantiate main application window.
FormMain window; FormMain main_window;
// Set correct information for main window. // Set correct information for main window.
window.setWindowTitle(APP_LONG_NAME); main_window.setWindowTitle(APP_LONG_NAME);
// Now is a good time to initialize dynamic keyboard shortcuts. // Now is a good time to initialize dynamic keyboard shortcuts.
DynamicShortcuts::load(window.getActions()); DynamicShortcuts::load(main_window.allActions());
// Display welcome dialog if application is launched for the first time. // Display welcome dialog if application is launched for the first time.
if (Settings::instance()->value(APP_CFG_GEN, "first_start", true).toBool()) { if (Settings::instance()->value(APP_CFG_GEN, "first_start", true).toBool()) {
Settings::instance()->setValue(APP_CFG_GEN, "first_start", false); Settings::instance()->setValue(APP_CFG_GEN, "first_start", false);
FormWelcome(&window).exec(); FormWelcome(&main_window).exec();
} }
// Display main window. // Display main window.
@ -102,21 +104,22 @@ int main(int argc, char *argv[]) {
false).toBool() && false).toBool() &&
SystemTrayIcon::isSystemTrayActivated()) { SystemTrayIcon::isSystemTrayActivated()) {
qDebug("Hiding the main window when the application is starting."); qDebug("Hiding the main window when the application is starting.");
window.hide(); main_window.hide();
} }
else { else {
qDebug("Showing the main window when the application is starting."); qDebug("Showing the main window when the application is starting.");
window.show(); main_window.show();
} }
// Display tray icon if it is enabled and available. // Display tray icon if it is enabled and available.
if (SystemTrayIcon::isSystemTrayActivated()) { if (SystemTrayIcon::isSystemTrayActivated()) {
SystemTrayIcon::instance()->show(); SystemTrayIcon::instance()->show();
main_window.tabWidget()->feedMessageViewer()->feedsView()->notifyWithCounts();
} }
// Setup single-instance behavior. // Setup single-instance behavior.
QObject::connect(&application, SIGNAL(messageReceived(QString)), QObject::connect(&application, SIGNAL(messageReceived(QString)),
&window, SLOT(processExecutionMessage(QString))); &main_window, SLOT(processExecutionMessage(QString)));
// Enter global event loop. // Enter global event loop.
return QtSingleApplication::exec(); return QtSingleApplication::exec();