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
)
# Add resources.
set(APP_RESOURCES
resources/rssguard_resources.qrc
)
# Add translations.
set(APP_TRANSLATIONS
localization/rssguard_en.ts
@ -397,7 +392,6 @@ set(APP_TEXT
# Wrap files, create moc files.
if(${USE_QT_5})
qt5_wrap_ui(APP_UI ${APP_FORMS})
qt5_add_resources(APP_RCC ${APP_RESOURCES})
# Load translations.
if(Qt5LinguistTools_FOUND)
@ -409,7 +403,6 @@ if(${USE_QT_5})
else(${USE_QT_5})
qt4_wrap_cpp(APP_MOC ${APP_HEADERS})
qt4_wrap_ui(APP_UI ${APP_FORMS})
qt4_add_resources(APP_RCC ${APP_RESOURCES})
# Load 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() {
if (Settings::instance()->type() == Settings::Portable) {
m_databasePath = qApp->applicationDirPath() +
m_databaseFilePath = qApp->applicationDirPath() +
QDir::separator() +
QString(APP_DB_PATH);
}
else {
m_databasePath = QDir::homePath() + QDir::separator() +
m_databaseFilePath = QDir::homePath() + QDir::separator() +
QString(APP_LOW_H_NAME) + QDir::separator() +
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() {
QSqlDatabase database = connection();
QSqlDatabase file_database = connection(objectName(), false);

View file

@ -15,7 +15,7 @@ class DatabaseFactory : public QObject {
// Returns absolute file path to database file.
inline QString getDatabasePath() {
return m_databasePath;
return m_databaseFilePath;
}
// If in-memory is true, then :memory: database is returned
@ -25,7 +25,11 @@ class DatabaseFactory : public QObject {
bool in_memory = true);
// 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
// to file-based database.
@ -47,7 +51,7 @@ class DatabaseFactory : public QObject {
QSqlDatabase initializeFileBasedDatabase(const QString &connection_name);
// Path to database file.
QString m_databasePath;
QString m_databaseFilePath;
// Is database file initialized?
bool m_fileBasedinitialized;

View file

@ -38,10 +38,6 @@ FeedsModel::~FeedsModel() {
delete m_rootItem;
}
QVariant FeedsModel::data(const QModelIndex &index, int role) const {
return itemForIndex(index)->data(index.column(), role);
}
QVariant FeedsModel::headerData(int section,
Qt::Orientation orientation,
int role) const {
@ -137,14 +133,6 @@ int FeedsModel::rowCount(const QModelIndex &parent) const {
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,
// vim ze to zhruba funguje ale je potreba pridat taky
// 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) {
QHash<int, FeedsModelRootItem*> assignments;
assignments.insert(NO_PARENT_CATEGORY, m_rootItem);

View file

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

View file

@ -24,11 +24,3 @@ FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other)
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();
// All types of categories offer these getters/setters.
Type type() const;
void setType(const Type &type);
inline Type type() const {
return m_type;
}
inline void setType(const Type &type) {
m_type = type;
}
protected:
Type m_type;

View file

@ -29,17 +29,6 @@ int FeedsModelFeed::countOfUnreadMessages() const {
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) {
switch (type) {
case StandardAtom10:

View file

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

View file

@ -12,17 +12,10 @@ FeedsModelRootItem::FeedsModelRootItem(FeedsModelRootItem *parent_item)
FeedsModelRootItem::~FeedsModelRootItem() {
qDebug("Destroying FeedsModelRootItem instance.");
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 {
return m_kind;
}
@ -31,10 +24,6 @@ QIcon FeedsModelRootItem::icon() const {
return m_icon;
}
FeedsModelRootItem *FeedsModelRootItem::child(int row) {
return m_childItems.value(row);
}
void FeedsModelRootItem::appendChild(FeedsModelRootItem *child) {
m_childItems.append(child);
child->setParent(this);

View file

@ -23,9 +23,18 @@ class FeedsModelRootItem {
virtual ~FeedsModelRootItem();
// Basic operations.
virtual FeedsModelRootItem *parent() const;
virtual void setParent(FeedsModelRootItem *parent_item);
virtual FeedsModelRootItem *child(int row);
inline virtual FeedsModelRootItem *parent() const {
return m_parentItem;
}
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 int childCount() const;
virtual int columnCount() const;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -46,7 +46,7 @@ SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
// Initialize icon.
setNumber();
setContextMenu(parent->getTrayMenu());
setContextMenu(parent->trayMenu());
// Create necessary connections.
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 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(linkMiddleClicked(QUrl)),
tab_widget, SLOT(addLinkedBrowser(QUrl)));

View file

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