File indexing completed on 2024-03-24 04:58:11
0001 /* 0002 This file is part of Choqok, the KDE micro-blogging client 0003 0004 SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #include "mainwindow.h" 0010 0011 #include "config-choqok.h" 0012 0013 #include <QAction> 0014 #include <QMenu> 0015 #include <QMenuBar> 0016 #include <QPushButton> 0017 #include <QSplashScreen> 0018 #include <QStandardPaths> 0019 #include <QStatusBar> 0020 #include <QTabBar> 0021 #include <QTabWidget> 0022 #include <QTimer> 0023 0024 #if HAVE_KGLOBALACCEL 0025 #include <KGlobalAccel> 0026 #endif 0027 #include <KActionCollection> 0028 #include <KLocalizedString> 0029 #include <KMessageBox> 0030 #include <KNotifyConfigWidget> 0031 #include <KCMultiDialog> 0032 #include <KStandardAction> 0033 #include <KXMLGUIFactory> 0034 0035 #include "accountmanager.h" 0036 #include "choqokappearancesettings.h" 0037 #include "choqokapplication.h" 0038 #include "choqokbehaviorsettings.h" 0039 #include "choqokdebug.h" 0040 #include "choqoktools.h" 0041 #include "choqokuiglobal.h" 0042 #include "mediamanager.h" 0043 #include "microblogwidget.h" 0044 #include "pluginmanager.h" 0045 #include "postwidget.h" 0046 #include "quickpost.h" 0047 #include "systrayicon.h" 0048 #include "uploadmediadialog.h" 0049 0050 MainWindow::MainWindow(ChoqokApplication *application) 0051 : Choqok::UI::MainWindow(), sysIcon(nullptr), quickWidget(nullptr), s_settingsDialog(nullptr), 0052 m_splash(nullptr), choqokMainButton(nullptr), app(application), 0053 microblogCounter(0), choqokMainButtonVisible(false) 0054 { 0055 qCDebug(CHOQOK); 0056 setAttribute(Qt::WA_DeleteOnClose, false); 0057 setAttribute(Qt::WA_QuitOnClose, false); 0058 0059 timelineTimer = new QTimer(this); 0060 setWindowTitle(i18n("Choqok")); 0061 connect(mainWidget, &QTabWidget::currentChanged, this, &MainWindow::slotCurrentBlogChanged); 0062 setCentralWidget(mainWidget); 0063 0064 setupActions(); 0065 updateSysTray(); 0066 statusBar()->show(); 0067 setupGUI(); 0068 0069 if (Choqok::BehaviorSettings::updateInterval() > 0) { 0070 mPrevUpdateInterval = Choqok::BehaviorSettings::updateInterval(); 0071 } else { 0072 mPrevUpdateInterval = 10; 0073 } 0074 0075 connect(timelineTimer, &QTimer::timeout, this, &MainWindow::updateTimelines); 0076 connect(this, &MainWindow::markAllAsRead, this, &MainWindow::slotMarkAllAsRead); 0077 connect(Choqok::AccountManager::self(), SIGNAL(accountAdded(Choqok::Account*)), 0078 this, SLOT(addBlog(Choqok::Account*))); 0079 connect(Choqok::AccountManager::self(), &Choqok::AccountManager::accountRemoved, 0080 this, &MainWindow::removeBlog); 0081 connect(Choqok::AccountManager::self(), &Choqok::AccountManager::allAccountsLoaded, 0082 this, &MainWindow::loadAllAccounts); 0083 0084 connect(Choqok::PluginManager::self(), &Choqok::PluginManager::pluginLoaded, 0085 this, &MainWindow::newPluginAvailable); 0086 0087 QTimer::singleShot(0, Choqok::PluginManager::self(), &Choqok::PluginManager::loadAllPlugins); 0088 // Choqok::AccountManager::self()->loadAllAccounts(); 0089 QTimer::singleShot(0, Choqok::AccountManager::self(), &Choqok::AccountManager::loadAllAccounts); 0090 0091 connect(this, &MainWindow::updateTimelines, this, &MainWindow::slotUpdateTimelines); 0092 0093 QPoint pos = Choqok::BehaviorSettings::position(); 0094 if (pos.x() != -1 && pos.y() != -1) { 0095 move(pos); 0096 } 0097 actionCollection()->action(QLatin1String("choqok_hide_menubar"))->setChecked(menuBar()->isHidden()); 0098 } 0099 0100 MainWindow::~MainWindow() 0101 { 0102 qCDebug(CHOQOK); 0103 0104 disconnect(this, &MainWindow::markAllAsRead, this, &MainWindow::slotMarkAllAsRead); 0105 disconnect(this, &MainWindow::updateTimelines, this, &MainWindow::slotUpdateTimelines); 0106 disconnect(Choqok::BehaviorSettings::self(), &Choqok::BehaviorSettings::configChanged, 0107 this, &MainWindow::slotBehaviorConfigChanged); 0108 disconnect(Choqok::AppearanceSettings::self(), &Choqok::AppearanceSettings::configChanged, 0109 this, &MainWindow::slotAppearanceConfigChanged); 0110 } 0111 0112 void MainWindow::loadAllAccounts() 0113 { 0114 qCDebug(CHOQOK); 0115 0116 if (Choqok::BehaviorSettings::showSplashScreen()) { 0117 const QPixmap splashpix(QStandardPaths::locate(QStandardPaths::DataLocation, QLatin1String("images/splash_screen.png"))); 0118 if (splashpix.isNull()) { 0119 qCCritical(CHOQOK) << "Splash screen pixmap is NULL!"; 0120 } else { 0121 m_splash = new QSplashScreen(splashpix, Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); 0122 m_splash->show(); 0123 } 0124 } 0125 0126 settingsChanged(); 0127 QList<Choqok::Account *> accList = Choqok::AccountManager::self()->accounts(); 0128 const int count = microblogCounter = accList.count(); 0129 if (count > 0) { 0130 for (Choqok::Account *ac: accList) { 0131 connect(ac, &Choqok::Account::status, this, &MainWindow::updateBlog); 0132 addBlog(ac, true); 0133 } 0134 qCDebug(CHOQOK) << "All accounts loaded."; 0135 if (Choqok::BehaviorSettings::updateInterval() > 0) { 0136 QTimer::singleShot(500, this, &MainWindow::updateTimelines); 0137 } 0138 } else { 0139 if (m_splash) { 0140 m_splash->finish(this); 0141 delete m_splash; 0142 m_splash = nullptr; 0143 } 0144 } 0145 ChoqokApplication::setStartingUp(false); 0146 createQuickPostDialog(); 0147 } 0148 0149 void MainWindow::newPluginAvailable(Choqok::Plugin *plugin) 0150 { 0151 qCDebug(CHOQOK); 0152 guiFactory()->addClient(plugin); 0153 } 0154 0155 void MainWindow::nextTab(int delta, Qt::Orientation orientation) 0156 { 0157 if (!isVisible()) { 0158 return; 0159 } 0160 QTabWidget *widget = nullptr; 0161 switch (orientation) { 0162 case Qt::Vertical: 0163 widget = mainWidget; 0164 break; 0165 case Qt::Horizontal: 0166 ///Commented for now! 0167 // Choqok::MicroBlogWidget * t = qobject_cast<Choqok::MicroBlogWidget*>( mainWidget->widget( mainWidget->currentIndex() )); 0168 // if(t) 0169 // widget = t->tabs; 0170 // else 0171 return; 0172 break; 0173 } 0174 if (!widget) { 0175 return; 0176 } 0177 0178 int count = widget->count(); 0179 int index = widget->currentIndex(); 0180 int page; 0181 if (delta > 0) { 0182 page = index > 0 ? index - 1 : count - 1; 0183 } else { 0184 page = index < count - 1 ? index + 1 : 0; 0185 } 0186 widget->setCurrentIndex(page); 0187 } 0188 0189 void MainWindow::setupActions() 0190 { 0191 actQuit = KStandardAction::quit(this, SLOT(slotQuit()), actionCollection()); 0192 prefs = KStandardAction::preferences(this, SLOT(slotConfigChoqok()), actionCollection()); 0193 0194 actUpdate = new QAction(QIcon::fromTheme(QLatin1String("view-refresh")), i18n("Update Timelines"), this); 0195 actionCollection()->addAction(QLatin1String("update_timeline"), actUpdate); 0196 actionCollection()->setDefaultShortcut(actUpdate, QKeySequence(Qt::Key_F5)); 0197 #if HAVE_KGLOBALACCEL 0198 KGlobalAccel::setGlobalShortcut(actUpdate, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_F5)); 0199 #endif 0200 connect(actUpdate, &QAction::triggered, this, &MainWindow::updateTimelines); 0201 0202 newTwit = new QAction(QIcon::fromTheme(QLatin1String("document-new")), i18n("Quick Post"), this); 0203 actionCollection()->addAction(QLatin1String("choqok_new_post"), newTwit); 0204 actionCollection()->setDefaultShortcut(newTwit, QKeySequence(Qt::CTRL | Qt::Key_T)); 0205 #if HAVE_KGLOBALACCEL 0206 KGlobalAccel::setGlobalShortcut(newTwit, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_T)); 0207 #endif 0208 connect(newTwit, &QAction::triggered, this, &MainWindow::triggerQuickPost); 0209 0210 QAction *markRead = new QAction(QIcon::fromTheme(QLatin1String("mail-mark-read")), i18n("Mark All As Read"), this); 0211 actionCollection()->addAction(QLatin1String("choqok_mark_as_read"), markRead); 0212 actionCollection()->setDefaultShortcut(markRead, QKeySequence(Qt::CTRL | Qt::Key_R)); 0213 connect(markRead, &QAction::triggered, this, &MainWindow::markAllAsRead); 0214 0215 showMain = new QAction(this); 0216 actionCollection()->addAction(QLatin1String("toggle_mainwin"), showMain); 0217 #if HAVE_KGLOBALACCEL 0218 KGlobalAccel::setGlobalShortcut(showMain, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_C)); 0219 #endif 0220 if (this->isVisible()) { 0221 showMain->setText(i18nc("@action", "Minimize")); 0222 } else { 0223 showMain->setText(i18nc("@action", "Restore")); 0224 } 0225 connect(showMain, &QAction::triggered, this, &MainWindow::toggleMainWindow); 0226 0227 QAction *act = KStandardAction::configureNotifications(this, SLOT(slotConfNotifications()), 0228 actionCollection()); 0229 actionCollection()->addAction(QLatin1String("settings_notifications"), act); 0230 0231 enableUpdates = new QAction(i18n("Enable Update Timer"), this); 0232 enableUpdates->setCheckable(true); 0233 actionCollection()->addAction(QLatin1String("choqok_enable_updates"), enableUpdates); 0234 actionCollection()->setDefaultShortcut(enableUpdates, QKeySequence(Qt::CTRL | Qt::Key_U)); 0235 connect(enableUpdates, &QAction::toggled, this, &MainWindow::setTimeLineUpdatesEnabled); 0236 0237 QAction *enableNotify = new QAction(i18n("Enable Notifications"), this); 0238 enableNotify->setCheckable(true); 0239 actionCollection()->addAction(QLatin1String("choqok_enable_notify"), enableNotify); 0240 actionCollection()->setDefaultShortcut(enableNotify, QKeySequence(Qt::CTRL | Qt::Key_N)); 0241 connect(enableNotify, &QAction::toggled, this, &MainWindow::setNotificationsEnabled); 0242 0243 QAction *hideMenuBar = new QAction(i18n("Hide Menubar"), this); 0244 hideMenuBar->setCheckable(true); 0245 actionCollection()->addAction(QLatin1String("choqok_hide_menubar"), hideMenuBar); 0246 actionCollection()->setDefaultShortcut(hideMenuBar, QKeySequence(Qt::ControlModifier | Qt::Key_M)); 0247 connect(hideMenuBar, &QAction::toggled, menuBar(), &QMenuBar::setHidden); 0248 connect(hideMenuBar, &QAction::toggled, this, &MainWindow::slotShowSpecialMenu); 0249 0250 QAction *clearAvatarCache = new QAction(QIcon::fromTheme(QLatin1String("edit-clear")), i18n("Clear Avatar Cache"), this); 0251 actionCollection()->addAction(QLatin1String("choqok_clear_avatar_cache"), clearAvatarCache); 0252 QString tip = i18n("You have to restart Choqok to load avatars again"); 0253 clearAvatarCache->setToolTip(tip); 0254 clearAvatarCache->setStatusTip(tip); 0255 connect(clearAvatarCache, &QAction::triggered, Choqok::MediaManager::self(), &Choqok::MediaManager::clearImageCache); 0256 0257 QAction *uploadMedium = new QAction(QIcon::fromTheme(QLatin1String("arrow-up")), i18n("Upload Medium..."), this); 0258 actionCollection()->addAction(QLatin1String("choqok_upload_medium"), uploadMedium); 0259 connect(uploadMedium, &QAction::triggered, this, &MainWindow::slotUploadMedium); 0260 } 0261 0262 void MainWindow::slotConfNotifications() 0263 { 0264 KNotifyConfigWidget::configure(this); 0265 } 0266 0267 void MainWindow::createQuickPostDialog() 0268 { 0269 quickWidget = new Choqok::UI::QuickPost(this); 0270 Choqok::UI::Global::setQuickPostWidget(quickWidget); 0271 quickWidget->setAttribute(Qt::WA_DeleteOnClose, false); 0272 if (sysIcon) { 0273 connect(quickWidget, &Choqok::UI::QuickPost::newPostSubmitted, sysIcon, &SysTrayIcon::slotJobDone); 0274 } 0275 Q_EMIT quickPostCreated(); 0276 } 0277 0278 void MainWindow::triggerQuickPost() 0279 { 0280 if (Choqok::AccountManager::self()->accounts().isEmpty()) { 0281 KMessageBox::error(this, i18n("No account created. You have to create an account before being able to make posts.")); 0282 return; 0283 } 0284 if (!quickWidget) { 0285 createQuickPostDialog(); 0286 } 0287 if (quickWidget->isVisible()) { 0288 quickWidget->hide(); 0289 } else { 0290 quickWidget->show(); 0291 } 0292 } 0293 0294 void MainWindow::slotConfigChoqok() 0295 { 0296 if (!s_settingsDialog) { 0297 s_settingsDialog = new KCMultiDialog(this); 0298 for (const auto& plugin : KPluginMetaData::findPlugins(QStringLiteral("choqok_kcms"))) { 0299 s_settingsDialog->addModule(plugin); 0300 } 0301 } 0302 s_settingsDialog->show(); 0303 connect(Choqok::BehaviorSettings::self(), &Choqok::BehaviorSettings::configChanged, 0304 this, &MainWindow::slotBehaviorConfigChanged); 0305 connect(Choqok::AppearanceSettings::self(), &Choqok::AppearanceSettings::configChanged, 0306 this, &MainWindow::slotAppearanceConfigChanged); 0307 } 0308 0309 void MainWindow::settingsChanged() 0310 { 0311 qCDebug(CHOQOK); 0312 if (Choqok::AccountManager::self()->accounts().count() < 1) { 0313 if (KMessageBox::questionYesNo(this, i18n("In order to use Choqok you need \ 0314 an account at one of the supported micro-blogging services.\n\ 0315 Would you like to add your account now?")) == KMessageBox::Yes) { 0316 slotConfigChoqok(); 0317 } 0318 } 0319 slotAppearanceConfigChanged(); 0320 slotBehaviorConfigChanged(); 0321 } 0322 0323 void MainWindow::slotAppearanceConfigChanged() 0324 { 0325 if (Choqok::AppearanceSettings::isCustomUi()) { 0326 Choqok::UI::PostWidget::setStyle(Choqok::AppearanceSettings::unreadForeColor() , 0327 Choqok::AppearanceSettings::unreadBackColor(), 0328 Choqok::AppearanceSettings::readForeColor() , 0329 Choqok::AppearanceSettings::readBackColor() , 0330 Choqok::AppearanceSettings::ownForeColor() , 0331 Choqok::AppearanceSettings::ownBackColor(), 0332 Choqok::AppearanceSettings::font()); 0333 } else { 0334 QPalette p = window()->palette(); 0335 Choqok::UI::PostWidget::setStyle(p.color(QPalette::WindowText) , p.color(QPalette::Window).lighter() , 0336 p.color(QPalette::WindowText) , p.color(QPalette::Window) , 0337 p.color(QPalette::WindowText) , p.color(QPalette::Window), 0338 font()); 0339 } 0340 0341 for (int i = 0; i < mainWidget->count(); ++i) { 0342 qobject_cast<Choqok::UI::MicroBlogWidget *>(mainWidget->widget(i))->settingsChanged(); 0343 } 0344 } 0345 0346 void MainWindow::updateSysTray() 0347 { 0348 if (Choqok::BehaviorSettings::enableSysTray()) { 0349 if (!sysIcon) { 0350 sysIcon = new SysTrayIcon(this); 0351 // sysIcon->show(); 0352 0353 ///SysTray Actions: 0354 sysIcon->contextMenu()->addAction(newTwit); 0355 // sysIcon->contextMenu()->addAction( uploadMedium ); 0356 sysIcon->contextMenu()->addAction(actUpdate); 0357 sysIcon->contextMenu()->addSeparator(); 0358 connect(enableUpdates, &QAction::toggled, sysIcon, &SysTrayIcon::setTimeLineUpdatesEnabled); 0359 sysIcon->contextMenu()->addAction(enableUpdates); 0360 sysIcon->setTimeLineUpdatesEnabled(enableUpdates->isChecked()); 0361 // sysIcon->contextMenu()->addAction( enableNotify ); 0362 sysIcon->contextMenu()->addAction(prefs); 0363 0364 sysIcon->contextMenu()->addSeparator(); 0365 sysIcon->contextMenu()->addAction(showMain); 0366 sysIcon->contextMenu()->addAction(actQuit); 0367 // connect( sysIcon, SIGNAL(quitSelected()), this, SLOT(slotQuit()) ); 0368 connect(sysIcon, &SysTrayIcon::scrollRequested, this, &MainWindow::nextTab); 0369 } 0370 } else { 0371 if (sysIcon) { 0372 if (isHidden()) { 0373 show(); 0374 } 0375 0376 delete sysIcon; 0377 sysIcon = nullptr; 0378 } 0379 } 0380 } 0381 0382 void MainWindow::slotBehaviorConfigChanged() 0383 { 0384 if (Choqok::BehaviorSettings::notifyEnabled()) { 0385 actionCollection()->action(QLatin1String("choqok_enable_notify"))->setChecked(true); 0386 } else { 0387 actionCollection()->action(QLatin1String("choqok_enable_notify"))->setChecked(false); 0388 } 0389 if (Choqok::BehaviorSettings::updateInterval() > 0) { 0390 timelineTimer->setInterval(Choqok::BehaviorSettings::updateInterval() * 60000); 0391 timelineTimer->start(); 0392 actionCollection()->action(QLatin1String("choqok_enable_updates"))->setChecked(true); 0393 } else { 0394 timelineTimer->stop(); 0395 actionCollection()->action(QLatin1String("choqok_enable_updates"))->setChecked(false); 0396 } 0397 0398 updateSysTray(); 0399 } 0400 0401 void MainWindow::slotQuit() 0402 { 0403 qCDebug(CHOQOK); 0404 Choqok::BehaviorSettings::setPosition(pos()); 0405 timelineTimer->stop(); 0406 Choqok::BehaviorSettings::self()->save(); 0407 app->quitChoqok(); 0408 } 0409 0410 void MainWindow::disableApp() 0411 { 0412 qCDebug(CHOQOK); 0413 timelineTimer->stop(); 0414 // qCDebug(CHOQOK)<<"timelineTimer stoped"; 0415 actionCollection()->action(QLatin1String("update_timeline"))->setEnabled(false); 0416 actionCollection()->action(QLatin1String("choqok_new_post"))->setEnabled(false); 0417 // actionCollection()->action( "choqok_search" )->setEnabled( false ); 0418 actionCollection()->action(QLatin1String("choqok_mark_as_read"))->setEnabled(false); 0419 // actionCollection()->action( "choqok_now_listening" )->setEnabled( false ); 0420 } 0421 0422 void MainWindow::enableApp() 0423 { 0424 qCDebug(CHOQOK); 0425 if (Choqok::BehaviorSettings::updateInterval() > 0) { 0426 timelineTimer->start(); 0427 // qCDebug(CHOQOK)<<"timelineTimer started"; 0428 } 0429 actionCollection()->action(QLatin1String("update_timeline"))->setEnabled(true); 0430 actionCollection()->action(QLatin1String("choqok_new_post"))->setEnabled(true); 0431 // actionCollection()->action( "choqok_search" )->setEnabled( true ); 0432 actionCollection()->action(QLatin1String("choqok_mark_as_read"))->setEnabled(true); 0433 // actionCollection()->action( "choqok_now_listening" )->setEnabled( true ); 0434 } 0435 0436 void MainWindow::addBlog(Choqok::Account *account, bool isStartup) 0437 { 0438 qCDebug(CHOQOK) << "Adding new Blog, Alias:" << account->alias() << "Blog:" << account->microblog()->serviceName(); 0439 0440 if (!account->isEnabled()) { 0441 oneMicroblogLoaded(); 0442 return; 0443 } 0444 0445 Choqok::UI::MicroBlogWidget *widget = account->microblog()->createMicroBlogWidget(account, this); 0446 connect(widget, &Choqok::UI::MicroBlogWidget::loaded, this, &MainWindow::oneMicroblogLoaded); 0447 connect(widget, &Choqok::UI::MicroBlogWidget::updateUnreadCount, this, &MainWindow::slotUpdateUnreadCount); 0448 widget->initUi(); 0449 0450 connect(widget, &Choqok::UI::MicroBlogWidget::showMe, this, &MainWindow::showBlog); 0451 0452 connect(this, &MainWindow::updateTimelines, widget, &Choqok::UI::MicroBlogWidget::updateTimelines); 0453 connect(this, &MainWindow::markAllAsRead, widget, &Choqok::UI::MicroBlogWidget::markAllAsRead); 0454 connect(this, &MainWindow::removeOldPosts, widget, &Choqok::UI::MicroBlogWidget::removeOldPosts); 0455 0456 mainWidget->addTab(widget, QIcon::fromTheme(account->microblog()->pluginIcon()), account->alias()); 0457 0458 if (!isStartup) { 0459 QTimer::singleShot(1500, widget, &Choqok::UI::MicroBlogWidget::updateTimelines); 0460 } 0461 enableApp(); 0462 updateTabbarHiddenState(); 0463 } 0464 0465 void MainWindow::updateBlog(Choqok::Account *account, bool enabled) 0466 { 0467 if (!enabled) { 0468 removeBlog(account->alias()); 0469 } else { 0470 addBlog(account); 0471 } 0472 } 0473 0474 void MainWindow::removeBlog(const QString &alias) 0475 { 0476 qCDebug(CHOQOK); 0477 for (int i = 0; i < mainWidget->count(); ++i) { 0478 Choqok::UI::MicroBlogWidget *tmp = qobject_cast<Choqok::UI::MicroBlogWidget *>(mainWidget->widget(i)); 0479 if (tmp->currentAccount()->alias() == alias) { 0480 mainWidget->removeTab(i); 0481 if (mainWidget->count() < 1) { 0482 disableApp(); 0483 } 0484 tmp->deleteLater(); 0485 updateTabbarHiddenState(); 0486 return; 0487 } 0488 } 0489 } 0490 0491 void MainWindow::updateTabbarHiddenState() 0492 { 0493 if (mainWidget->count() <= 1 && !choqokMainButtonVisible) { 0494 mainWidget->tabBar()->hide(); 0495 } else { 0496 mainWidget->tabBar()->show(); 0497 } 0498 } 0499 0500 void MainWindow::slotUpdateUnreadCount(int change, int sum) 0501 { 0502 qCDebug(CHOQOK) << "Change:" << change << "Sum:" << sum; 0503 Choqok::UI::MicroBlogWidget *wd = qobject_cast<Choqok::UI::MicroBlogWidget *>(sender()); 0504 0505 if (sysIcon) { 0506 sysIcon->updateUnreadCount(change); 0507 } 0508 0509 int accountsSum = 0; 0510 for (int i = 0; i < mainWidget->tabBar()->count(); ++i) { 0511 Choqok::UI::MicroBlogWidget *tab = qobject_cast<Choqok::UI::MicroBlogWidget *>(mainWidget->widget(i)); 0512 0513 accountsSum += tab->unreadCount(); 0514 0515 if (wd == tab) { 0516 if (sum > 0) { 0517 mainWidget->setTabText(i, wd->currentAccount()->alias() + QStringLiteral(" (%1)").arg(sum)); 0518 } else { 0519 mainWidget->setTabText(i, wd->currentAccount()->alias()); 0520 } 0521 } 0522 } 0523 0524 if (accountsSum > 0) { 0525 setWindowTitle(i18n("Choqok (%1)", accountsSum)); 0526 } else { 0527 setWindowTitle(i18n("Choqok")); 0528 } 0529 } 0530 0531 void MainWindow::showBlog() 0532 { 0533 mainWidget->setCurrentWidget(qobject_cast<QWidget *>(sender())); 0534 if (!this->isVisible()) { 0535 this->show(); 0536 } 0537 this->raise(); 0538 } 0539 0540 void MainWindow::setTimeLineUpdatesEnabled(bool isEnabled) 0541 { 0542 qCDebug(CHOQOK); 0543 if (isEnabled) { 0544 if (mPrevUpdateInterval > 0) { 0545 Choqok::BehaviorSettings::setUpdateInterval(mPrevUpdateInterval); 0546 } 0547 Q_EMIT updateTimelines(); 0548 timelineTimer->start(Choqok::BehaviorSettings::updateInterval() * 60000); 0549 // qCDebug(CHOQOK)<<"timelineTimer started"; 0550 } else { 0551 mPrevUpdateInterval = Choqok::BehaviorSettings::updateInterval(); 0552 timelineTimer->stop(); 0553 // qCDebug(CHOQOK)<<"timelineTimer stoped"; 0554 Choqok::BehaviorSettings::setUpdateInterval(0); 0555 } 0556 } 0557 0558 void MainWindow::setNotificationsEnabled(bool isEnabled) 0559 { 0560 qCDebug(CHOQOK); 0561 if (isEnabled) { 0562 Choqok::BehaviorSettings::setNotifyEnabled(true); 0563 } else { 0564 Choqok::BehaviorSettings::setNotifyEnabled(false); 0565 } 0566 } 0567 0568 void MainWindow::toggleMainWindow() 0569 { 0570 if (this->isVisible()) { 0571 hide(); 0572 } else { 0573 show(); 0574 } 0575 } 0576 0577 void MainWindow::hideEvent(QHideEvent *event) 0578 { 0579 Choqok::UI::MainWindow::hideEvent(event); 0580 showMain->setText(i18n("Restore")); 0581 } 0582 0583 void MainWindow::showEvent(QShowEvent *event) 0584 { 0585 Choqok::UI::MainWindow::showEvent(event); 0586 showMain->setText(i18n("Minimize")); 0587 } 0588 0589 void MainWindow::slotMarkAllAsRead() 0590 { 0591 setWindowTitle(i18n("Choqok")); 0592 if (sysIcon) { 0593 sysIcon->resetUnreadCount(); 0594 } 0595 for (int i = 0; i < mainWidget->count(); ++i) { 0596 Choqok::UI::MicroBlogWidget *wd = qobject_cast<Choqok::UI::MicroBlogWidget *>(mainWidget->widget(i)); 0597 mainWidget->setTabText(i, wd->currentAccount()->alias()); 0598 } 0599 } 0600 0601 void MainWindow::slotCurrentBlogChanged(int) 0602 { 0603 Choqok::UI::MicroBlogWidget *wd = qobject_cast<Choqok::UI::MicroBlogWidget *>(mainWidget->currentWidget()); 0604 if (wd) { 0605 wd->setFocus(); 0606 Q_EMIT currentMicroBlogWidgetChanged(wd); 0607 } 0608 } 0609 0610 void MainWindow::oneMicroblogLoaded() 0611 { 0612 qCDebug(CHOQOK); 0613 --microblogCounter; 0614 if (microblogCounter < 1) { 0615 //Everything loaded, So splash screen should be deleted! 0616 delete m_splash; 0617 m_splash = nullptr; 0618 if (Choqok::BehaviorSettings::showMainWinOnStart()) { 0619 this->show(); 0620 } 0621 } else { 0622 if (m_splash) { 0623 m_splash->showMessage(QString()); //Workaround for Qt 4.8 splash bug 0624 } 0625 } 0626 } 0627 0628 void MainWindow::slotUpdateTimelines() 0629 { 0630 if (Choqok::AccountManager::self()->accounts().count()) { 0631 showStatusMessage(i18n("Loading timelines...")); 0632 } 0633 } 0634 0635 void MainWindow::slotUploadMedium() 0636 { 0637 QPointer<Choqok::UI::UploadMediaDialog> dlg = new Choqok::UI::UploadMediaDialog(this); 0638 dlg->show(); 0639 } 0640 0641 void MainWindow::slotShowSpecialMenu(bool show) 0642 { 0643 if (show) { 0644 if (!choqokMainButton) { 0645 choqokMainButton = new QPushButton(QIcon::fromTheme(QLatin1String("choqok")), QString(), mainWidget); 0646 QMenu *menu = new QMenu(i18n("Choqok"), choqokMainButton); 0647 menu->addAction(actionCollection()->action(QLatin1String("choqok_new_post"))); 0648 menu->addAction(actionCollection()->action(QLatin1String("update_timeline"))); 0649 menu->addAction(actionCollection()->action(QLatin1String("choqok_mark_as_read"))); 0650 menu->addAction(actionCollection()->action(QLatin1String("choqok_upload_medium"))); 0651 menu->addSeparator(); 0652 menu->addAction(actionCollection()->action(QLatin1String("choqok_enable_updates"))); 0653 menu->addAction(actionCollection()->action(QLatin1String("choqok_hide_menubar"))); 0654 menu->addAction(prefs); 0655 menu->addSeparator(); 0656 menu->addAction(showMain); 0657 menu->addAction(actQuit); 0658 choqokMainButton->setMenu(menu); 0659 } 0660 mainWidget->setCornerWidget(choqokMainButton/*, Qt::TopLeftCorner*/); 0661 choqokMainButton->show(); 0662 choqokMainButtonVisible = true; 0663 } else { 0664 choqokMainButtonVisible = false; 0665 mainWidget->setCornerWidget(nullptr/*, Qt::TopLeftCorner*/); 0666 } 0667 updateTabbarHiddenState(); 0668 } 0669 0670 #include "moc_mainwindow.cpp"