Refactoring.

This commit is contained in:
Martin Rotter 2016-08-15 14:23:52 +02:00
parent efd4ab8014
commit f9f5aa234f
9 changed files with 40 additions and 64 deletions

View File

@ -105,10 +105,12 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message> &messages) {
<< feed->id() << " in thread: \'"
<< QThread::currentThreadId() << "\'.";
int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages);
if (!m_stopUpdate) {
int updated_messages = messages.isEmpty() ? 0 : feed->updateMessages(messages);
if (updated_messages > 0) {
m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages));
if (updated_messages > 0) {
m_results.appendUpdatedFeed(QPair<QString,int>(feed->title(), updated_messages));
}
}
qDebug("Made progress in feed updates, total feeds count %d/%d (id of feed is %d).", m_feedsUpdated, m_feedsTotalCount, feed->id());

View File

@ -76,34 +76,6 @@ FeedsModel::~FeedsModel() {
delete m_rootItem;
}
/*
void FeedsModel::onFeedUpdatesStarted() {
//: Text display in status bar when feed update is started.
qApp->mainForm()->statusBar()->showProgressFeeds(0, tr("Feed update started"));
emit feedsUpdateStarted();
}
void FeedsModel::onFeedUpdatesProgress(const Feed *feed, int current, int total) {
// Some feed got updated.
qApp->mainForm()->statusBar()->showProgressFeeds((current * 100.0) / total,
//: Text display in status bar when particular feed is updated.
tr("Updated feed '%1'").arg(feed->title()));
}
void FeedsModel::onFeedUpdatesFinished(const FeedDownloadResults &results) {
qApp->feedUpdateLock()->unlock();
qApp->mainForm()->statusBar()->clearProgressFeeds();
if (!results.updatedFeeds().isEmpty()) {
// Now, inform about results via GUI message/notification.
qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, 0, false);
}
emit feedsUpdateFinished();
}
*/
QMimeData *FeedsModel::mimeData(const QModelIndexList &indexes) const {
QMimeData *mime_data = new QMimeData();
QByteArray encoded_data;

View File

@ -45,7 +45,7 @@
#define ID_RECYCLE_BIN -2
#define TRAY_ICON_BUBBLE_TIMEOUT 20000
#define KEY_MESSAGES_VIEW "messages_view_column_"
#define CLOSE_LOCK_TIMEOUT 1500
#define CLOSE_LOCK_TIMEOUT 500
#define DOWNLOAD_TIMEOUT 5000
#define MESSAGES_VIEW_DEFAULT_COL 170
#define FEEDS_VIEW_COLUMN_COUNT 2

View File

@ -331,7 +331,10 @@ void FormMain::updateAccountsMenu() {
}
void FormMain::onFeedUpdatesFinished(FeedDownloadResults results) {
Q_UNUSED(results)
statusBar()->clearProgressFeeds();
tabWidget()->feedMessageViewer()->messagesView()->reloadSelections(false);
}
void FormMain::onFeedUpdatesStarted() {

View File

@ -214,7 +214,6 @@ void FeedMessageViewer::createConnections() {
// to reload selections.
connect(m_feedsView->sourceModel(), SIGNAL(reloadMessageListRequested(bool)),
m_messagesView, SLOT(reloadSelections(bool)));
connect(m_feedsView->sourceModel(), SIGNAL(feedsUpdateFinished()), this, SLOT(onFeedsUpdateFinished()));
}
void FeedMessageViewer::initialize() {
@ -298,7 +297,3 @@ void FeedMessageViewer::refreshVisualProperties() {
m_toolBarFeeds->setToolButtonStyle(button_style);
m_toolBarMessages->setToolButtonStyle(button_style);
}
void FeedMessageViewer::onFeedsUpdateFinished() {
m_messagesView->reloadSelections(false);
}

View File

@ -73,9 +73,6 @@ class FeedMessageViewer : public TabContent {
void refreshVisualProperties();
private slots:
// Called when feed update finishes.
void onFeedsUpdateFinished();
// Switches visibility of feed list and related
// toolbar.
void switchFeedComponentVisibility();

View File

@ -225,26 +225,30 @@ void Application::restoreDatabaseSettings(bool restore_database, bool restore_se
void Application::processExecutionMessage(const QString &message) {
qDebug("Received '%s' execution message from another application instance.", qPrintable(message));
foreach (const QString &msg, message.split(ARGUMENTS_LIST_SEPARATOR)) {
if (msg == APP_IS_RUNNING) {
showGuiMessage(APP_NAME, tr("Application is already running."), QSystemTrayIcon::Information);
mainForm()->display();
}
else if (msg == APP_QUIT_INSTANCE) {
quit();
}
else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) {
// Application was running, and someone wants to add new feed.
StandardServiceRoot *root = qApp->feedReader()->feedsModel()->standardServiceRoot();
const QStringList messages = message.split(ARGUMENTS_LIST_SEPARATOR);
if (root != nullptr) {
root->checkArgumentForFeedAdding(msg);
if (messages.contains(APP_QUIT_INSTANCE)) {
quit();
}
else {
foreach (const QString &msg, message.split(ARGUMENTS_LIST_SEPARATOR)) {
if (msg == APP_IS_RUNNING) {
showGuiMessage(APP_NAME, tr("Application is already running."), QSystemTrayIcon::Information);
mainForm()->display();
}
else {
showGuiMessage(tr("Cannot add feed"),
tr("Feed cannot be added because standard RSS/ATOM account is not enabled."),
QSystemTrayIcon::Warning, qApp->mainForm(),
true);
else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) {
// Application was running, and someone wants to add new feed.
StandardServiceRoot *root = qApp->feedReader()->feedsModel()->standardServiceRoot();
if (root != nullptr) {
root->checkArgumentForFeedAdding(msg);
}
else {
showGuiMessage(tr("Cannot add feed"),
tr("Feed cannot be added because standard RSS/ATOM account is not enabled."),
QSystemTrayIcon::Warning, qApp->mainForm(),
true);
}
}
}
}
@ -322,9 +326,11 @@ void Application::onAboutToQuit() {
#endif
qApp->feedReader()->stop();
database()->saveDatabase();
mainForm()->saveSize();
if (mainForm() != nullptr) {
mainForm()->saveSize();
}
if (locked_safely) {
// Application obtained permission to close in a safe way.
@ -356,8 +362,6 @@ void Application::onFeedUpdatesProgress(const Feed *feed, int current, int total
}
void Application::onFeedUpdatesFinished(FeedDownloadResults results) {
qApp->feedUpdateLock()->unlock();
if (!results.updatedFeeds().isEmpty()) {
// Now, inform about results via GUI message/notification.
qApp->showGuiMessage(tr("New messages downloaded"), results.overview(10), QSystemTrayIcon::NoIcon, 0, false);

View File

@ -85,6 +85,7 @@ void FeedReader::updateFeeds(const QList<Feed*> &feeds) {
connect(m_feedDownloader, &FeedDownloader::updateFinished, this, &FeedReader::feedUpdatesFinished);
connect(m_feedDownloader, &FeedDownloader::updateProgress, this, &FeedReader::feedUpdatesProgress);
connect(m_feedDownloader, &FeedDownloader::updateStarted, this, &FeedReader::feedUpdatesStarted);
connect(m_feedDownloader, &FeedDownloader::updateFinished, qApp->feedUpdateLock(), &Mutex::unlock);
// Connections are made, start the feed downloader thread.
m_feedDownloaderThread->start();

View File

@ -31,14 +31,16 @@ class Mutex : public QObject {
virtual ~Mutex();
// Main methods.
void lock();
bool tryLock();
bool tryLock(int timeout);
void unlock();
// Identifies if mutes is locked or not.
bool isLocked() const;
public slots:
void lock();
void unlock();
protected:
// These methods set proper value for m_isLocked and emit signals.
void setLocked();