diff --git a/CMakeLists.txt b/CMakeLists.txt index da7c78b..03152e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,47 +1,44 @@ project( rsibreak ) cmake_minimum_required (VERSION 3.5.0 FATAL_ERROR) set (QT_MIN_VERSION "5.10.0") find_package(ECM 5.18.0 REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS DBus) find_package(KF5 REQUIRED COMPONENTS Config ConfigWidgets Crash DBusAddons DocTools IconThemes I18n IdleTime Notifications NotifyConfig TextWidgets XmlGui WindowSystem ) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(FeatureSummary) include(ECMAddAppIcon) include(ECMInstallIcons) -if (EXISTS "${CMAKE_SOURCE_DIR}/.git") - add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000) - add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x060000) -endif() + add_subdirectory( icons ) add_subdirectory( doc ) add_subdirectory( src ) include(CTest) if(BUILD_TESTING) enable_testing() add_subdirectory( test ) endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/src/breakcontrol.cpp b/src/breakcontrol.cpp index 416853d..c140f36 100644 --- a/src/breakcontrol.cpp +++ b/src/breakcontrol.cpp @@ -1,134 +1,133 @@ /* Copyright (C) 2009-2010 Tom Albers Copyright (C) 2010 Juan Luis Baptiste 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) any later version. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "breakcontrol.h" #include #include #include #include #include #include #include #include -#include #include #include #include BreakControl::BreakControl( QWidget* parent, Qt::WindowType type ) : QWidget( parent, type ) { m_vbox = new QVBoxLayout; m_textLabel = new QLabel( this ); m_textLabel->setAlignment( Qt::AlignHCenter ); QWidget* hbox = new QWidget( this ); QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox); hboxHBoxLayout->setContentsMargins(0, 0, 0, 0); hboxHBoxLayout->setSpacing( 25 ); m_skipButton = new QPushButton( i18n( "Skip Break" ), hbox ); hboxHBoxLayout->addWidget(m_skipButton); QSize sizeSkip( m_skipButton->size() ); - m_skipButton->setIcon( QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize))); + m_skipButton->setIcon( SmallIcon( "dialog-cancel" ) ); m_skipButton->setFixedHeight( sizeSkip.height() ); connect(m_skipButton, &QPushButton::clicked, this, &BreakControl::skip); m_postponeButton = new QPushButton( i18n( "Postpone Break" ), hbox ); hboxHBoxLayout->addWidget(m_postponeButton); QSize sizePostpone(m_postponeButton->size()); - m_postponeButton->setIcon(QIcon::fromTheme(QStringLiteral("go-next")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize))); + m_postponeButton->setIcon(SmallIcon("go-next")); m_postponeButton->setFixedHeight(sizePostpone.height()); connect(m_postponeButton, &QPushButton::clicked, this, &BreakControl::postpone); m_lockButton = new QPushButton( i18n( "Lock Screen" ), hbox ); hboxHBoxLayout->addWidget(m_lockButton); QSize sizeLock( m_skipButton->size() ); m_lockButton->setFixedHeight( sizeLock.height() ); - m_lockButton->setIcon( QIcon::fromTheme(QStringLiteral("system-lock-screen")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)) ); + m_lockButton->setIcon( SmallIcon( "system-lock-screen" ) ); connect(m_lockButton, &QPushButton::clicked, this, &BreakControl::slotLock); m_vbox->addWidget( m_textLabel ); m_vbox->addWidget( hbox ); setLayout( m_vbox ); connect( qApp, &QGuiApplication::screenAdded, this, &BreakControl::slotCenterIt ); connect( qApp, &QGuiApplication::screenRemoved, this, &BreakControl::slotCenterIt ); slotCenterIt(); } void BreakControl::slotCenterIt() { const QRect r( QGuiApplication::primaryScreen()->geometry() ); const QPoint center( r.width() / 2 - sizeHint().width() / 2, r.y() ); move( center ); } void BreakControl::slotLock() { emit lock(); } void BreakControl::setText( const QString& text ) { m_textLabel->setText( text ); } void BreakControl::showMinimize( bool show ) { m_skipButton->setVisible( show ); } void BreakControl::showLock( bool show ) { m_lockButton->setVisible( show ); } void BreakControl::showPostpone( bool show ) { m_postponeButton->setVisible( show ); } void BreakControl::paintEvent( QPaintEvent *event ) { if ( event->type() == QEvent::Paint ) { int margin = 3; QPainterPath box; box.moveTo( rect().topLeft() ); box.lineTo( rect().bottomLeft() ); box.lineTo( rect().bottomRight() ); box.lineTo( rect().topRight() ); box.closeSubpath(); QColor highlight = palette().highlight().color(); highlight.setAlphaF( 0.7 ); QPen pen( highlight ); pen.setWidth( margin ); QPainter painter( this ); painter.setPen( pen ); painter.drawPath( box ); } } diff --git a/src/rsidock.cpp b/src/rsidock.cpp index d26ac0f..33245a3 100644 --- a/src/rsidock.cpp +++ b/src/rsidock.cpp @@ -1,242 +1,239 @@ /* Copyright (C) 2005-2006 Tom Albers Copyright (C) 2011 Aurélien Gâteau Orginal copied from ksynaptics: Copyright (C) 2004 Nadeem Hasan 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) any later version. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "rsidock.h" #include "setup.h" #include "rsistatwidget.h" #include "rsistats.h" #include -#include #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template static QAction *doAddAction(QMenu *menu, const QString &text, Object *receiver, Func func) { QAction *action = menu->addAction(text); QObject::connect(action, &QAction::triggered, receiver, func); return action; } template static QAction *doAddAction(QMenu *menu, const QIcon &icon, const QString &text, Object *receiver, Func func) { QAction *action = doAddAction(menu, text, receiver, func); action->setIcon(icon); return action; } RSIDock::RSIDock( QObject *parent ) : KStatusNotifierItem( parent ), m_suspended( false ) , m_statsDialog( 0 ), m_statsWidget( 0 ) { setCategory(ApplicationStatus); setStatus(Active); const KAboutData &aboutData = KAboutData::applicationData(); setTitle( aboutData.displayName() ); setToolTipTitle( aboutData.displayName() ); m_help = new KHelpMenu( 0, aboutData ); QMenu* menu = contextMenu(); doAddAction( menu, QIcon::fromTheme( "kde" ), i18n( "About &KDE" ), m_help, &KHelpMenu::aboutKDE ); doAddAction( menu, i18n( "&About RSIBreak" ), m_help, &KHelpMenu::aboutApplication ); doAddAction( menu, QIcon::fromTheme( "help-contents" ), i18n( "RSIBreak &Handbook" ), m_help, &KHelpMenu::appHelpActivated ); menu->addSeparator(); doAddAction( menu, QIcon::fromTheme( "tools-report-bug" ), i18n( "&Report Bug..." ), m_help, &KHelpMenu::reportBug ); doAddAction( menu, i18n( "Switch application &language..." ), m_help, &KHelpMenu::switchApplicationLanguage ); menu->addSeparator(); - m_suspendItem = doAddAction(menu, QIcon::fromTheme(QStringLiteral("media-playback-pause")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "&Suspend RSIBreak" ), this, &RSIDock::slotToggleSuspend ); - - doAddAction(menu, QIcon::fromTheme(QStringLiteral("view-statistics")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "&Usage Statistics" ), this, &RSIDock::slotShowStatistics ); - doAddAction(menu, QIcon::fromTheme(QStringLiteral("preferences-desktop-notification")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "Configure &Notifications..." ), this, &RSIDock::slotConfigureNotifications ); + m_suspendItem = doAddAction(menu, SmallIcon( "media-playback-pause" ), i18n( "&Suspend RSIBreak" ), this, &RSIDock::slotToggleSuspend ); + doAddAction(menu, SmallIcon( "view-statistics" ), i18n( "&Usage Statistics" ), this, &RSIDock::slotShowStatistics ); + doAddAction(menu, SmallIcon( "preferences-desktop-notification" ), i18n( "Configure &Notifications..." ), this, &RSIDock::slotConfigureNotifications ); doAddAction(menu, QIcon::fromTheme( "configure" ), i18n( "&Configure RSIBreak..." ), this, &RSIDock::slotConfigure ); connect(this, &RSIDock::activateRequested, this, &RSIDock::slotShowStatistics); } RSIDock::~RSIDock() { delete m_help; delete m_statsWidget; delete m_statsDialog; m_statsWidget = 0; } void RSIDock::doResume() { if ( m_suspended ) slotToggleSuspend(); } void RSIDock::doSuspend() { if ( !m_suspended ) slotToggleSuspend(); } void RSIDock::slotConfigureNotifications() { KNotifyConfigWidget::configure( 0 ); } void RSIDock::slotConfigure() { // don't think it is needed, because setup is not accessed after the // exec call, but better safe than crash. QPointer setup = new Setup( 0 ); emit dialogEntered(); if ( setup->exec() == QDialog::Accepted ) emit configChanged( !m_suspended ); delete setup; if ( !m_suspended ) emit dialogLeft(); } void RSIDock::slotToggleSuspend() { if ( m_suspended ) { emit suspend( false ); setIconByName( "rsibreak0" ); - m_suspendItem->setIcon( QIcon::fromTheme(QStringLiteral("media-playback-pause")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)) ); + m_suspendItem->setIcon( SmallIcon( "media-playback-pause" ) ); m_suspendItem->setText( i18n( "&Suspend RSIBreak" ) ); } else { emit suspend( true ); setIconByName( "rsibreakx" ); - m_suspendItem->setIcon( QIcon::fromTheme(QStringLiteral("media-playback-start")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)) ); + m_suspendItem->setIcon( SmallIcon( "media-playback-start" ) ); m_suspendItem->setText( i18n( "&Resume RSIBreak" ) ); } m_suspended = !m_suspended; } void RSIDock::slotShowStatistics() { if ( !m_statsDialog ) { m_statsDialog = new QDialog( 0 ); m_statsDialog->setWindowTitle( i18n( "Usage Statistics" ) ); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); QVBoxLayout *mainLayout = new QVBoxLayout; m_statsDialog->setLayout(mainLayout); QPushButton *user1Button = new QPushButton; buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole); connect(buttonBox, &QDialogButtonBox::accepted, m_statsDialog, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, m_statsDialog, &QDialog::reject); user1Button->setText(i18n( "Reset" )); m_statsWidget = new RSIStatWidget( m_statsDialog ); connect(user1Button, &QPushButton::clicked, this, &RSIDock::slotResetStats); mainLayout->addWidget(m_statsWidget); mainLayout->addWidget(buttonBox); } if ( m_statsDialog->isVisible() && KWindowInfo(m_statsDialog->winId(), NET::WMDesktop ).isOnCurrentDesktop() ) { m_statsDialog->hide(); } else { m_statsDialog->show(); if ( !m_statsDialog->isActiveWindow() ) KWindowSystem::forceActiveWindow( m_statsDialog->winId() ); m_statsDialog->raise(); } } void RSIDock::slotResetStats() { int i = KMessageBox::warningContinueCancel( 0, i18n( "This will reset all statistics to zero. " "Is that what you want?" ), i18n( "Reset the statistics" ), KGuiItem( i18n( "Reset" ) ), KStandardGuiItem::cancel(), "resetStatistics" ); if ( i == KMessageBox::Continue ) RSIGlobals::instance()->stats()->reset(); } static QString colorizedText( const QString& text, const QColor& color ) { return QString(" %2") .arg(color.name(), text.toHtmlEscaped()); } void RSIDock::setCounters( int tiny_left, int big_left ) { if ( m_suspended ) setToolTipSubTitle( i18n( "Suspended" ) ); else { QColor tinyColor = RSIGlobals::instance()->getTinyBreakColor( tiny_left ); RSIGlobals::instance()->stats()->setColor( LAST_TINY_BREAK, tinyColor ); QColor bigColor = RSIGlobals::instance()-> getBigBreakColor( big_left ); RSIGlobals::instance()->stats()->setColor( LAST_BIG_BREAK, bigColor ); // Only add the line for the tiny break when there is not // a big break planned at the same time. QStringList lines; if ( tiny_left != big_left ) { QString formattedText = RSIGlobals::instance()->formatSeconds( tiny_left ); if ( !formattedText.isNull() ) { lines << colorizedText( i18n( "%1 remaining until next short break", formattedText ), tinyColor ); } } // do the same for the big break if ( big_left > 0 ) lines << colorizedText( i18n( "%1 remaining until next long break", RSIGlobals::instance()->formatSeconds( big_left ) ), bigColor ); setToolTipSubTitle(lines.join("
")); } } diff --git a/src/rsirelaxpopup.cpp b/src/rsirelaxpopup.cpp index 928265f..59dd9b0 100644 --- a/src/rsirelaxpopup.cpp +++ b/src/rsirelaxpopup.cpp @@ -1,178 +1,176 @@ /* Copyright (C) 2005 Bram Schoenmakers Copyright (C) 2005-2007,2010 Tom Albers Copyright (C) 2010 Juan Luis Baptiste 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) any later version. 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, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "rsirelaxpopup.h" #include #include #include #include -#include -#include #include #include #include #include #include #include #include RSIRelaxPopup::RSIRelaxPopup( QWidget *parent ) : QObject( parent ) , m_wasShown( false ) { m_popup = new PassivePopup( parent ); QWidget *vbox = new QWidget( m_popup ); QVBoxLayout *vboxVBoxLayout = new QVBoxLayout(vbox); vboxVBoxLayout->setContentsMargins(0, 0, 0, 0); vboxVBoxLayout->setSpacing( 5 ); m_message = new QLabel( vbox ); vboxVBoxLayout->addWidget(m_message); QWidget *hbox = new QWidget( vbox ); QHBoxLayout *hboxHBoxLayout = new QHBoxLayout(hbox); hboxHBoxLayout->setContentsMargins(0, 0, 0, 0); vboxVBoxLayout->addWidget(hbox); hboxHBoxLayout->setSpacing( 15 ); m_progress = new QProgressBar( hbox ); hboxHBoxLayout->addWidget(m_progress); m_progress->setFormat( "%v" ); m_progress->setRange( 0, 0 ); - m_skipbutton = new QPushButton( QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "Skip Break" ), hbox ); + m_skipbutton = new QPushButton( SmallIcon( "dialog-cancel" ), i18n( "Skip Break" ), hbox ); hboxHBoxLayout->addWidget(m_skipbutton); m_skipbutton->setToolTip( i18n( "Skip this break" ) ); connect(m_skipbutton, &QPushButton::clicked, this, &RSIRelaxPopup::skip); - m_postponebutton = new QPushButton( QIcon::fromTheme(QStringLiteral("go-next")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "Postpone Break" ), hbox ); + m_postponebutton = new QPushButton( SmallIcon( "go-next" ), i18n( "Postpone Break" ), hbox ); hboxHBoxLayout->addWidget(m_postponebutton); m_postponebutton->setToolTip( i18n( "Postpone this break" ) ); connect(m_postponebutton, &QPushButton::clicked, this, &RSIRelaxPopup::postpone); - m_lockbutton = new QPushButton( QIcon::fromTheme(QStringLiteral("system-lock-screen")).pixmap(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize)), i18n( "Lock Screen" ), hbox ); + m_lockbutton = new QPushButton( SmallIcon( "system-lock-screen" ), i18n( "Lock Screen" ), hbox ); hboxHBoxLayout->addWidget(m_lockbutton); m_lockbutton->setToolTip( i18n( "Lock the session" ) ); connect(m_lockbutton, &QPushButton::clicked, this, &RSIRelaxPopup::lock); m_popup->setTimeout( 0 ); // no auto close m_popup->setView( vbox ); readSettings(); } RSIRelaxPopup::~RSIRelaxPopup() {} void RSIRelaxPopup::relax( int n, bool bigBreakNext ) { /* Counts how many times a request for relax resets due to detected activity. */ static int resetcount = 0; /* If n increases compared to the last call, we want a new request for a relax moment. */ if ( n >= m_progress->value() ) { m_progress->setRange( 0, n ); resetcount += 1; if ( n > m_progress->value() ) flash(); else if ( resetcount % 4 == 0 ) // flash regularly when the user keeps working flash(); } if ( n > 0 ) { QString text = i18n( "Please relax for %1", KFormat().formatSpelloutDuration( n * 1000 ) ); if ( bigBreakNext ) text.append( '\n' + i18n( "Note: next break is a big break" ) ); m_message->setText( text ); m_progress->setValue( n ); if ( resetcount == 1 ) m_popup->show(); } else { m_popup->setVisible( false ); resetcount = 0; m_wasShown = false; } } void RSIRelaxPopup::flash() { if ( !m_useFlash ) return; QTimer::singleShot( 500, this, &RSIRelaxPopup::unflash ); QPalette normal; normal.setColor( QPalette::Inactive, QPalette::WindowText, KColorScheme( QPalette::Active, KColorScheme::Selection ).background().color() ); normal.setColor( QPalette::Inactive, QPalette::Window, KColorScheme( QPalette::Active, KColorScheme::Selection ).foreground().color() ); m_popup->setPalette( normal ); } void RSIRelaxPopup::unflash() { QPalette normal; m_popup->setPalette( normal ); } void RSIRelaxPopup::slotReadConfig() { readSettings(); } void RSIRelaxPopup::readSettings() { KConfigGroup config = KSharedConfig::openConfig()->group( "Popup Settings" ); m_useFlash = config.readEntry( "UseFlash", true ); } void RSIRelaxPopup::setSkipButtonHidden( bool b ) { m_skipbutton->setHidden( b ); } void RSIRelaxPopup::setLockButtonHidden( bool b ) { m_lockbutton->setHidden( b ); } void RSIRelaxPopup::setPostponeButtonHidden( bool b ) { m_postponebutton->setHidden( b ); } void RSIRelaxPopup::setSuspended( bool suspended ) { if ( suspended ) { m_wasShown = m_popup->isVisible(); m_popup->hide(); } else if (m_wasShown) { m_popup->show(); } }