diff --git a/choqok/systrayicon.cpp b/choqok/systrayicon.cpp index ca2cb3a4..5ba0a479 100644 --- a/choqok/systrayicon.cpp +++ b/choqok/systrayicon.cpp @@ -1,150 +1,150 @@ /* This file is part of Choqok, the KDE micro-blogging client Copyright (C) 2008-2012 Mehrdad Momeny This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/ */ #include "systrayicon.h" #include #include #include #include #include #include "choqokdebug.h" SysTrayIcon::SysTrayIcon(Choqok::UI::MainWindow *parent) : KStatusNotifierItem(parent), _mainwin(parent), isOffline(false) { qCDebug(CHOQOK); unread = 0; setAssociatedWidget(parent); setCategory(ApplicationStatus); setStandardActionsEnabled(false); // setStatus(Active); setIconByName(currentIconName()); } SysTrayIcon::~SysTrayIcon() { qCDebug(CHOQOK); } void SysTrayIcon::resetUnreadCount() { updateUnreadCount(-unread); } QString SysTrayIcon::currentIconName() { if (isOffline) { return QLatin1String("choqok_offline"); } else { return QLatin1String("choqok"); } } void SysTrayIcon::updateUnreadCount(int changeOfUnreadPosts) { qCDebug(CHOQOK); unread += changeOfUnreadPosts; if (unread <= 0) { setIconByName(currentIconName()); unread = 0; setStatus(Passive); } else { setStatus(Active); int oldWidth = 22; QString countStr = QString::number(unread); QFont f = QFontDatabase::systemFont(QFontDatabase::GeneralFont); f.setBold(true); auto pointSize = f.pointSizeF(); QFontMetrics fm(f); - int w = fm.width(countStr); + int w = fm.horizontalAdvance(countStr); if (w > (oldWidth - 2)) { pointSize *= float(oldWidth - 2) / float(w); f.setPointSizeF(pointSize); } // overlay QPixmap overlayImg = QIcon::fromTheme(currentIconName()).pixmap(22, 22); QPainter p(&overlayImg); p.setFont(f); fm = QFontMetrics(f); QRect boundingRect = fm.tightBoundingRect(countStr); boundingRect.adjust(0, 0, 0, 2); boundingRect.setHeight(qMin(boundingRect.height(), oldWidth)); boundingRect.moveTo((oldWidth - boundingRect.width()) / 2, ((oldWidth - boundingRect.height()) / 2) - 1); p.setOpacity(0.7); QBrush br(QColor(255, 255, 255), Qt::SolidPattern); p.setBrush(br); p.setPen(QColor(255, 255, 255)); p.drawRoundedRect(boundingRect, 2.0, 2.0); p.setBrush(Qt::NoBrush); p.setPen(QColor(0, 0, 0)); p.setOpacity(1.0); p.drawText(overlayImg.rect(), Qt::AlignCenter, countStr); setIconByPixmap(overlayImg); } this->setToolTip(QLatin1String("choqok"), i18n("Choqok"), i18np("1 unread post", "%1 unread posts", unread)); } void SysTrayIcon::setTimeLineUpdatesEnabled(bool isEnabled) { if (isEnabled) { setToolTip(QLatin1String("choqok"), i18n("Choqok"), QString()); setIconByName(QLatin1String("choqok")); } else { setToolTip(QLatin1String("choqok"), i18n("Choqok - Disabled"), QString()); setIconByName(QLatin1String("choqok_offline")); } isOffline = !isEnabled; updateUnreadCount(0); } void SysTrayIcon::slotJobDone(Choqok::JobResult result) { qCDebug(CHOQOK); if (result == Choqok::Success) { setOverlayIconByName(QLatin1String("task-complete")); } else { setOverlayIconByName(QLatin1String("task-reject")); } QTimer::singleShot(5000, this, &SysTrayIcon::slotRestoreIcon); } void SysTrayIcon::slotRestoreIcon() { setOverlayIconByName(QString()); updateUnreadCount(0); } int SysTrayIcon::unreadCount() const { return unread; } diff --git a/helperlibs/twitterapihelper/twitterapimicroblogwidget.cpp b/helperlibs/twitterapihelper/twitterapimicroblogwidget.cpp index 1d85208f..145e6138 100644 --- a/helperlibs/twitterapihelper/twitterapimicroblogwidget.cpp +++ b/helperlibs/twitterapihelper/twitterapimicroblogwidget.cpp @@ -1,289 +1,289 @@ /* This file is part of Choqok, the KDE micro-blogging client Copyright (C) 2008-2012 Mehrdad Momeny This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/ */ #include "twitterapimicroblogwidget.h" #include #include #include #include #include #include #include #include #include "account.h" #include "composerwidget.h" #include "twitterapiaccount.h" #include "twitterapidebug.h" #include "twitterapimicroblog.h" #include "twitterapisearchtimelinewidget.h" class TwitterApiMicroBlogWidget::Private { public: Private(Choqok::Account *acc) : btnCloseSearch(nullptr) { qCDebug(CHOQOK); mBlog = qobject_cast(acc->microblog()); this->account = qobject_cast(acc); } TwitterApiMicroBlog *mBlog; TwitterApiAccount *account; QToolButton *btnCloseSearch; }; QIcon addTextToIcon(const QIcon &icon, const QString &text, const QSize &result_size , const QPalette &palette) { QIcon result; QPixmap pixmap = icon.pixmap(result_size); QPainter painter(&pixmap); QFont font; font.setWeight(result_size.height() / 3); font.setBold(true); painter.setFont(font); - int textWidth = painter.fontMetrics().width(text); + int textWidth = painter.fontMetrics().horizontalAdvance(text); QRect rct(0 , 0 , textWidth , result_size.height() / 2); painter.setRenderHint(QPainter::Antialiasing); painter.setPen(palette.color(QPalette::Active , QPalette::HighlightedText)); painter.drawText(rct , Qt::AlignTop | Qt::AlignLeft , text); result.addPixmap(pixmap , QIcon::Active); return result; } TwitterApiMicroBlogWidget::TwitterApiMicroBlogWidget(Choqok::Account *account, QWidget *parent) : MicroBlogWidget(account, parent), d(new Private(account)) { qCDebug(CHOQOK); connect(account, &Choqok::Account::modified, this, &TwitterApiMicroBlogWidget::slotAccountModified); connect(d->mBlog->searchBackend(), &TwitterApiSearch::searchResultsReceived, this, &TwitterApiMicroBlogWidget::slotSearchResultsReceived); connect(d->mBlog, &TwitterApiMicroBlog::saveTimelines, this, &TwitterApiMicroBlogWidget::saveSearchTimelinesState); loadSearchTimelinesState(); } void TwitterApiMicroBlogWidget::initUi() { qCDebug(CHOQOK); Choqok::UI::MicroBlogWidget::initUi(); connect(timelinesTabWidget(), (void (Choqok::UI::ChoqokTabBar::*)(QWidget*,const QPoint&))&Choqok::UI::ChoqokTabBar::contextMenu, this, &TwitterApiMicroBlogWidget::slotContextMenu); // connect(timelinesTabWidget(), SIGNAL(currentChanged(int)), SLOT(slotCurrentTimelineChanged(int)) ); // d->btnCloseSearch->setIcon(QIcon::fromTheme("tab-close")); // d->btnCloseSearch->setAutoRaise(true); // d->btnCloseSearch->setToolTip(i18nc("Close a timeline", "Close Timeline")); // d->btnCloseSearch->setFixedWidth( 32 ); // timelinesTabWidget()->setTabAlongsideWidget( d->btnCloseSearch ); // connect(d->btnCloseSearch, SIGNAL(clicked(bool)), SLOT(slotCloseCurrentSearch()) ); // slotCurrentTimelineChanged(timelinesTabWidget()->currentIndex()); } TwitterApiMicroBlogWidget::~TwitterApiMicroBlogWidget() { delete d; } void TwitterApiMicroBlogWidget::slotSearchResultsReceived(const SearchInfo &info, QList< Choqok::Post * > &postsList) { qCDebug(CHOQOK); if (info.account == currentAccount()) { qCDebug(CHOQOK) << postsList.count(); QString name = QStringLiteral("%1%2").arg(d->mBlog->searchBackend()->optionCode(info.option)).arg(info.query); if (mSearchTimelines.contains(name)) { mSearchTimelines.value(name)->addNewPosts(postsList); } else { if (postsList.isEmpty()) { addSearchTimelineWidgetToUi(name, info)->addPlaceholderMessage(i18n("(The search result is empty.)")); } else { addSearchTimelineWidgetToUi(name, info)->addNewPosts(postsList); } } } } TwitterApiSearchTimelineWidget *TwitterApiMicroBlogWidget::addSearchTimelineWidgetToUi(const QString &name, const SearchInfo &info) { qCDebug(CHOQOK); TwitterApiSearchTimelineWidget *mbw = d->mBlog->createSearchTimelineWidget(currentAccount(), name, info, this); if (mbw) { mbw->setObjectName(name); mSearchTimelines.insert(name, mbw); timelines().insert(name, mbw); timelinesTabWidget()->addTab(mbw, name); QString textToAdd = name; if (textToAdd.contains(QLatin1Char(':'))) { QStringList splitted = textToAdd.split(QLatin1Char(':')); textToAdd = splitted.first().at(0) + QLatin1Char(':') + splitted[1].left(3); } else { textToAdd = textToAdd.left(4); } QIcon icon = addTextToIcon(QIcon::fromTheme(QLatin1String("edit-find")), textToAdd, QSize(40, 40), palette()); mbw->setTimelineIcon(icon); timelinesTabWidget()->setTabIcon(timelinesTabWidget()->indexOf(mbw), icon); connect(mbw, SIGNAL(updateUnreadCount(int)), this, SLOT(slotUpdateUnreadCount(int))); connect(mbw, &TwitterApiSearchTimelineWidget::closeMe, this, &TwitterApiMicroBlogWidget::slotCloseCurrentSearch); if (composer()) { connect(mbw, SIGNAL(forwardResendPost(QString)), composer(), SLOT(setText(QString))); connect(mbw, &TwitterApiSearchTimelineWidget::forwardReply, composer(), &Choqok::UI::ComposerWidget::setText); } timelinesTabWidget()->setCurrentWidget(mbw); } else { qCDebug(CHOQOK) << "Cannot Create a new TimelineWidget for timeline " << name; return nullptr; } if (timelinesTabWidget()->count() == 1) { timelinesTabWidget()->setTabBarHidden(true); } else { timelinesTabWidget()->setTabBarHidden(false); } return mbw; } void TwitterApiMicroBlogWidget::slotCloseCurrentSearch() { Choqok::UI::TimelineWidget *stw = qobject_cast(sender()); if (!stw) { stw = qobject_cast(timelinesTabWidget()->currentWidget()); } closeSearch(stw); } void TwitterApiMicroBlogWidget::slotAccountModified(Choqok::Account *account) { for (const QString &timeline: account->microblog()->timelineNames()) { if (account->timelineNames().contains(timeline)) { if (!timelines().contains(timeline)) { addTimelineWidgetToUi(timeline); } } else if (timelines().contains(timeline)) { Choqok::UI::TimelineWidget *tm = timelines().take(timeline); tm->deleteLater(); } } } void TwitterApiMicroBlogWidget::saveSearchTimelinesState() { qCDebug(CHOQOK); int count = currentAccount()->configGroup()->readEntry("SearchCount", 0); int i = 0; while (i < count) { currentAccount()->configGroup()->deleteEntry(QLatin1String("Search") + QString::number(i)); ++i; } i = 0; for (TwitterApiSearchTimelineWidget *tm: mSearchTimelines.values()) { currentAccount()->configGroup()->writeEntry(QLatin1String("Search") + QString::number(i), tm->searchInfo().toString()); ++i; } currentAccount()->configGroup()->writeEntry("SearchCount", i); } void TwitterApiMicroBlogWidget::loadSearchTimelinesState() { qCDebug(CHOQOK); int count = currentAccount()->configGroup()->readEntry(QLatin1String("SearchCount"), 0); int i = 0; while (i < count) { SearchInfo info; if (info.fromString(currentAccount()->configGroup()->readEntry(QLatin1String("Search") + QString::number(i), QString()))) { qobject_cast(currentAccount()->microblog())->searchBackend()->requestSearchResults(info); } ++i; } } void TwitterApiMicroBlogWidget::slotContextMenu(QWidget *w, const QPoint &pt) { qCDebug(CHOQOK); Choqok::UI::TimelineWidget *sWidget = qobject_cast(w); QMenu menu; QAction *mar = nullptr; QAction *ac = nullptr; if (sWidget->unreadCount() > 0) { mar = new QAction(QIcon::fromTheme(QLatin1String("mail-mark-read")), i18n("Mark timeline as read"), &menu); menu.addAction(mar); } if (sWidget->isClosable()) { ac = new QAction(QIcon::fromTheme(QLatin1String("tab-close")), i18n("Close Timeline"), &menu); QAction *closeAll = new QAction(QIcon::fromTheme(QLatin1String("tab-close")), i18n("Close All"), &menu); connect(closeAll, &QAction::triggered, this, &TwitterApiMicroBlogWidget::closeAllSearches); menu.addAction(ac); menu.addAction(closeAll); } QAction *res = menu.exec(pt); if (ac && res == ac) { closeSearch(sWidget); } else if (res == mar) { sWidget->markAllAsRead(); } } void TwitterApiMicroBlogWidget::closeSearch(Choqok::UI::TimelineWidget *searchWidget) { if (!searchWidget) { return; } searchWidget->markAllAsRead(); TwitterApiSearchTimelineWidget *tst = qobject_cast(searchWidget); timelinesTabWidget()->removePage(searchWidget); if (tst) { QString name = mSearchTimelines.key(tst); mSearchTimelines.value(name)->close(); mSearchTimelines.remove(name); timelines().remove(name); } else { QStringList lst = d->account->timelineNames(); lst.removeOne(searchWidget->timelineName()); d->account->setTimelineNames(lst); d->account->writeConfig(); timelines().remove(timelines().key(searchWidget)); searchWidget->close(); } } void TwitterApiMicroBlogWidget::closeAllSearches() { for (TwitterApiSearchTimelineWidget *searchWidget: mSearchTimelines.values()) { closeSearch(searchWidget); } for (Choqok::UI::TimelineWidget *widget: timelines().values()) { if (widget->isClosable()) { closeSearch(widget); } } } diff --git a/libchoqok/ui/microblogwidget.cpp b/libchoqok/ui/microblogwidget.cpp index e5e4d499..2672f45a 100644 --- a/libchoqok/ui/microblogwidget.cpp +++ b/libchoqok/ui/microblogwidget.cpp @@ -1,455 +1,455 @@ /* This file is part of Choqok, the KDE micro-blogging client Copyright (C) 2008-2012 Mehrdad Momeny This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see http://www.gnu.org/licenses/ */ #include "microblogwidget.h" #include #include #include #include #include #include #include #include #include #include #include "account.h" #include "choqokappearancesettings.h" #include "choqoktextedit.h" #include "choqokuiglobal.h" #include "composerwidget.h" #include "libchoqokdebug.h" #include "notifymanager.h" #include "timelinewidget.h" namespace Choqok { namespace UI { QIcon addNumToIcon(const QIcon &big , int number , const QSize &result_size , const QPalette &palette) { QIcon result; QList mods; mods << QIcon::Active /*<< QIcon::Disabled << QIcon::Selected*/; for (const QIcon::Mode &m: mods) { QPixmap pixmap = big.pixmap(result_size); QPainter painter(&pixmap); QFont font; font.setWeight(result_size.height() / 2); font.setBold(true); font.setItalic(true); painter.setFont(font); QString numberStr = QString::number(number); - int textWidth = painter.fontMetrics().width(numberStr) + 6; + int textWidth = painter.fontMetrics().horizontalAdvance(numberStr) + 6; if (textWidth < result_size.width() / 2) { textWidth = result_size.width() / 2; } QRect rct(result_size.width() - textWidth , result_size.width() / 2 , textWidth , result_size.height() / 2); QPointF center(rct.x() + rct.width() / 2 , rct.y() + rct.height() / 2); QPainterPath cyrcle_path; cyrcle_path.moveTo(center); cyrcle_path.arcTo(rct, 0, 360); painter.setRenderHint(QPainter::Antialiasing); painter.fillPath(cyrcle_path , palette.color(QPalette::Active , QPalette::Window)); painter.setPen(palette.color(QPalette::Active , QPalette::Text)); painter.drawText(rct , Qt::AlignHCenter | Qt::AlignVCenter , QString::number(number)); result.addPixmap(pixmap , m); } return result; } class MicroBlogWidget::Private { public: Private(Account *acc) : account(acc), blog(acc->microblog()), composer(nullptr), btnMarkAllAsRead(nullptr) { } Account *account; MicroBlog *blog; QPointer composer; QMap timelines; Choqok::UI::ChoqokTabBar *timelinesTabWidget; QLabel *latestUpdate; QPushButton *btnMarkAllAsRead; QHBoxLayout *toolbar; QFrame *toolbar_widget; }; MicroBlogWidget::MicroBlogWidget(Account *account, QWidget *parent) : QWidget(parent), d(new Private(account)) { qCDebug(CHOQOK); connect(d->blog, &MicroBlog::timelineDataReceived, this, &MicroBlogWidget::newTimelineDataRecieved); connect(d->blog, &MicroBlog::error, this, &MicroBlogWidget::error); connect(d->blog, &MicroBlog::errorPost, this, &MicroBlogWidget::errorPost); } Account *MicroBlogWidget::currentAccount() const { return d->account; } void MicroBlogWidget::initUi() { d->toolbar_widget = new QFrame(); d->toolbar_widget->setFrameShape(QFrame::StyledPanel); d->toolbar_widget->setFrameShadow(QFrame::Sunken); QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *toolbar_layout = new QVBoxLayout(d->toolbar_widget); toolbar_layout->addLayout(createToolbar()); d->timelinesTabWidget = new Choqok::UI::ChoqokTabBar(this); d->timelinesTabWidget->setLinkedTabBar(true); d->timelinesTabWidget->setTabCloseActivatePrevious(true); d->timelinesTabWidget->setExtraWidget(d->toolbar_widget , Choqok::UI::ChoqokTabBar::Top); if (!d->account->isReadOnly()) { setComposerWidget(d->blog->createComposerWidget(currentAccount(), this)); } layout->addWidget(d->timelinesTabWidget); this->layout()->setContentsMargins(0, 0, 0, 0); connect(currentAccount(), &Account::modified, this, &MicroBlogWidget::slotAccountModified); initTimelines(); } void MicroBlogWidget::setComposerWidget(ComposerWidget *widget) { if (d->composer) { d->composer->deleteLater(); } if (!widget) { d->composer = nullptr; return; } d->composer = widget; d->composer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); qobject_cast(d->toolbar_widget->layout())->insertWidget(1, d->composer); for (TimelineWidget *mbw: d->timelines) { connect(mbw, SIGNAL(forwardResendPost(QString)), d->composer, SLOT(setText(QString))); connect(mbw, &TimelineWidget::forwardReply, d->composer, &ComposerWidget::setText); } } MicroBlogWidget::~MicroBlogWidget() { qCDebug(CHOQOK); delete d; } TimelineWidget *MicroBlogWidget::currentTimeline() { return qobject_cast(d->timelinesTabWidget->currentWidget()); } uint MicroBlogWidget::unreadCount() const { uint sum = 0; for (TimelineWidget *wd: d->timelines) { sum += wd->unreadCount(); } return sum; } void MicroBlogWidget::settingsChanged() { for (TimelineWidget *wd: d->timelines) { wd->settingsChanged(); } } void MicroBlogWidget::updateTimelines() { qCDebug(CHOQOK) << d->account->alias(); d->account->microblog()->updateTimelines(currentAccount()); } void MicroBlogWidget::removeOldPosts() { for (TimelineWidget *wd: d->timelines) { wd->removeOldPosts(); } } void MicroBlogWidget::newTimelineDataRecieved(Choqok::Account *theAccount, const QString &type, QList< Choqok::Post * > data) { if (theAccount != currentAccount()) { return; } qCDebug(CHOQOK) << d->account->alias() << ":" << type; d->latestUpdate->setText(QTime::currentTime().toString()); if (d->timelines.contains(type)) { d->timelines.value(type)->addNewPosts(data); } else { if (TimelineWidget *wd = addTimelineWidgetToUi(type)) { wd->addNewPosts(data); } } } void MicroBlogWidget::initTimelines() { qCDebug(CHOQOK); for (const QString &timeline: d->account->timelineNames()) { addTimelineWidgetToUi(timeline); } // qCDebug(CHOQOK)<<"========== Emiting loaded()"; Q_EMIT loaded(); } TimelineWidget *MicroBlogWidget::addTimelineWidgetToUi(const QString &name) { TimelineWidget *mbw = d->blog->createTimelineWidget(d->account, name, this); if (mbw) { Choqok::TimelineInfo *info = currentAccount()->microblog()->timelineInfo(name); d->timelines.insert(name, mbw); d->timelinesTabWidget->addTab(mbw, info->name); d->timelinesTabWidget->setTabIcon(d->timelinesTabWidget->indexOf(mbw), QIcon::fromTheme(info->icon)); connect(mbw, SIGNAL(updateUnreadCount(int)), this, SLOT(slotUpdateUnreadCount(int))); if (d->composer) { connect(mbw, SIGNAL(forwardResendPost(QString)), d->composer, SLOT(setText(QString))); connect(mbw, &TimelineWidget::forwardReply, d->composer, &ComposerWidget::setText); } slotUpdateUnreadCount(mbw->unreadCount(), mbw); } else { qCDebug(CHOQOK) << "Cannot Create a new TimelineWidget for timeline " << name; return nullptr; } if (d->timelinesTabWidget->count() == 1) { d->timelinesTabWidget->setTabBarHidden(true); } else { d->timelinesTabWidget->setTabBarHidden(false); } return mbw; } void MicroBlogWidget::slotUpdateUnreadCount(int change, Choqok::UI::TimelineWidget *widget) { qCDebug(CHOQOK) << change; int sum = 0; for (TimelineWidget *mbw: d->timelines) { sum += mbw->unreadCount(); } if (change != 0) { Q_EMIT updateUnreadCount(change, sum); } if (sum > 0) { if (!d->btnMarkAllAsRead) { d->btnMarkAllAsRead = new QPushButton(this); d->btnMarkAllAsRead->setIcon(QIcon::fromTheme(QLatin1String("mail-mark-read"))); d->btnMarkAllAsRead->setIconSize(QSize(14, 14)); d->btnMarkAllAsRead->setToolTip(i18n("Mark all timelines as read")); d->btnMarkAllAsRead->setMaximumWidth(d->btnMarkAllAsRead->height()); connect(d->btnMarkAllAsRead, &QPushButton::clicked, this, &MicroBlogWidget::markAllAsRead); d->toolbar->insertWidget(1, d->btnMarkAllAsRead); } } else { d->btnMarkAllAsRead->deleteLater(); d->btnMarkAllAsRead = nullptr; } TimelineWidget *wd = qobject_cast(sender()); if (!wd) { wd = widget; } if (wd) { qCDebug(CHOQOK) << wd->unreadCount(); int tabIndex = d->timelinesTabWidget->indexOf(wd); if (tabIndex == -1) { return; } if (wd->unreadCount() > 0) { d->timelinesTabWidget->setTabIcon(tabIndex , addNumToIcon(timelinesTabWidget()->tabIcon(tabIndex) , wd->unreadCount() , QSize(40, 40) , palette())); d->timelinesTabWidget->setTabText(tabIndex, wd->timelineInfoName() + QStringLiteral(" (%1)").arg(wd->unreadCount())); } else { if (!wd->timelineIconName().isEmpty()) { d->timelinesTabWidget->setTabIcon(tabIndex , QIcon::fromTheme(wd->timelineIconName())); } else { d->timelinesTabWidget->setTabIcon(tabIndex , wd->timelineIcon()); } d->timelinesTabWidget->setTabText(tabIndex, wd->timelineInfoName()); } } } void MicroBlogWidget::markAllAsRead() { if (d->btnMarkAllAsRead) { d->btnMarkAllAsRead->deleteLater(); d->btnMarkAllAsRead = nullptr; } for (TimelineWidget *wd: d->timelines) { wd->markAllAsRead(); int tabIndex = d->timelinesTabWidget->indexOf(wd); if (tabIndex == -1) { continue; } d->timelinesTabWidget->setTabText(tabIndex, wd->timelineInfoName()); } } ComposerWidget *MicroBlogWidget::composer() { return d->composer; } QMap< QString, TimelineWidget * > &MicroBlogWidget::timelines() { return d->timelines; } Choqok::UI::ChoqokTabBar *MicroBlogWidget::timelinesTabWidget() { return d->timelinesTabWidget; } void MicroBlogWidget::error(Choqok::Account *theAccount, MicroBlog::ErrorType errorType, const QString &errorMsg, MicroBlog::ErrorLevel level) { if (theAccount == d->account) { switch (level) { case MicroBlog::Critical: KMessageBox::error(Choqok::UI::Global::mainWindow(), errorMsg, MicroBlog::errorString(errorType)); break; case MicroBlog::Normal: NotifyManager::error(errorMsg, MicroBlog::errorString(errorType)); break; default: // emit showStatusMessage(errorMsg); if (Choqok::UI::Global::mainWindow()->statusBar()) { Choqok::UI::Global::mainWindow()->statusBar()->showMessage(errorMsg); } break; }; } } void MicroBlogWidget::errorPost(Choqok::Account *theAccount, Choqok::Post *, MicroBlog::ErrorType errorType, const QString &errorMsg, MicroBlog::ErrorLevel level) { if (theAccount == d->account) { switch (level) { case MicroBlog::Critical: KMessageBox::error(Choqok::UI::Global::mainWindow(), errorMsg, MicroBlog::errorString(errorType)); break; case MicroBlog::Normal: NotifyManager::error(errorMsg, MicroBlog::errorString(errorType)); break; default: // emit showStatusMessage(errorMsg); if (Choqok::UI::Global::mainWindow()->statusBar()) { Choqok::UI::Global::mainWindow()->statusBar()->showMessage(errorMsg); } break; }; } } QLayout *MicroBlogWidget::createToolbar() { d->toolbar = new QHBoxLayout; QPushButton *btnActions = new QPushButton(i18n("More"), this); QLabel *lblLatestUpdate = new QLabel(i18n("Latest update:"), this); lblLatestUpdate->setAlignment(Qt::AlignRight | Qt::AlignVCenter); d->latestUpdate = new QLabel(QTime::currentTime().toString(), this); QFont fnt = lblLatestUpdate->font(); fnt.setPointSize(fnt.pointSize() - 1); lblLatestUpdate->setFont(fnt); fnt.setBold(true); d->latestUpdate->setFont(fnt); btnActions->setMenu(d->account->microblog()->createActionsMenu(d->account)); d->toolbar->addWidget(btnActions); d->toolbar->addSpacerItem(new QSpacerItem(1, 10, QSizePolicy::Expanding)); d->toolbar->addWidget(lblLatestUpdate); d->toolbar->addWidget(d->latestUpdate); return d->toolbar; } void MicroBlogWidget::slotAbortAllJobs() { currentAccount()->microblog()->abortAllJobs(currentAccount()); composer()->abort(); } void MicroBlogWidget::keyPressEvent(QKeyEvent *e) { if (e->key() == Qt::Key_Escape && composer()) { composer()->abort(); } QWidget::keyPressEvent(e); } void MicroBlogWidget::setFocus() { if (composer()) { composer()->editor()->setFocus(Qt::OtherFocusReason); } else { QWidget::setFocus(); } } void MicroBlogWidget::slotAccountModified(Account *theAccount) { if (theAccount == currentAccount()) { if (theAccount->isReadOnly()) { if (composer()) { setComposerWidget(nullptr); } } else if (!composer()) { setComposerWidget(theAccount->microblog()->createComposerWidget(theAccount, this)); } int sum = 0; for (TimelineWidget *mbw: d->timelines) { sum += mbw->unreadCount(); } Q_EMIT updateUnreadCount(0, sum); } } QLabel *MicroBlogWidget::latestUpdate() { return d->latestUpdate; } } }