Commit 2563abd9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

astyle-kdelibs

parent 84874493
This diff is collapsed.
......@@ -33,16 +33,19 @@
#include <QPoint>
#include <QTimer>
namespace Akonadi {
class Item;
namespace Akonadi
{
class Item;
}
namespace KIdentityManagement {
class IdentityManager;
namespace KIdentityManagement
{
class IdentityManager;
}
namespace CalendarSupport {
class IncidenceViewer;
namespace CalendarSupport
{
class IncidenceViewer;
}
class ReminderTreeItem;
......@@ -57,17 +60,17 @@ class QVBoxLayout;
class AlarmDialog : public QDialog
{
Q_OBJECT
public:
explicit AlarmDialog( const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent = 0 );
Q_OBJECT
public:
explicit AlarmDialog(const Akonadi::ETMCalendar::Ptr &calendar, QWidget *parent = 0);
~AlarmDialog();
void addIncidence( const Akonadi::Item &incidence, const QDateTime &reminderAt,
const QString &displayText );
void setRemindAt( const QDateTime &dt );
void addIncidence(const Akonadi::Item &incidence, const QDateTime &reminderAt,
const QString &displayText);
void setRemindAt(const QDateTime &dt);
void eventNotification();
public slots:
public slots:
void slotOk(); // suspend
void slotUser1(); // edit
void slotUser2(); // dismiss all
......@@ -89,40 +92,40 @@ class AlarmDialog : public QDialog
*/
void slotCalendarChanged();
signals:
void reminderCount( int count );
signals:
void reminderCount(int count);
private Q_SLOTS:
private Q_SLOTS:
void update();
void popupItemMenu( const QPoint &point );
void popupItemMenu(const QPoint &point);
protected:
void keyPressEvent( QKeyEvent *e );
void closeEvent( QCloseEvent * );
protected:
void keyPressEvent(QKeyEvent *e);
void closeEvent(QCloseEvent *);
private:
static KDateTime triggerDateForIncidence( const KCalCore::Incidence::Ptr &inc,
const QDateTime &reminderAt,
QString &displayStr );
private:
static KDateTime triggerDateForIncidence(const KCalCore::Incidence::Ptr &inc,
const QDateTime &reminderAt,
QString &displayStr);
// Removes each Incidence-X group that has one of the specified uids
void removeFromConfig( const QList<Akonadi::Item::Id> & );
void removeFromConfig(const QList<Akonadi::Item::Id> &);
// Opens through dbus, @deprecated
bool openIncidenceEditorThroughKOrganizer( const KCalCore::Incidence::Ptr &incidence );
bool openIncidenceEditorThroughKOrganizer(const KCalCore::Incidence::Ptr &incidence);
// opens directly
bool openIncidenceEditorNG( const Akonadi::Item &incidence );
bool openIncidenceEditorNG(const Akonadi::Item &incidence);
bool startKOrganizer();
ReminderTreeItem *searchByItem( const Akonadi::Item &incidence );
ReminderTreeItem *searchByItem(const Akonadi::Item &incidence);
void setTimer();
void dismiss( QList<ReminderTreeItem *> selections );
void dismiss(QList<ReminderTreeItem *> selections);
int activeCount();
QList<ReminderTreeItem *> selectedItems() const;
void updateButtons();
void toggleDetails( QTreeWidgetItem *item );
void showDetails( QTreeWidgetItem *item );
void toggleDetails(QTreeWidgetItem *item);
void showDetails(QTreeWidgetItem *item);
Akonadi::ETMCalendar::Ptr mCalendar;
QTreeWidget *mIncidenceTree;
......
......@@ -41,177 +41,177 @@
#include <QMenu>
AlarmDockWindow::AlarmDockWindow()
: KStatusNotifierItem( 0 )
: KStatusNotifierItem(0)
{
// Read the autostart status from the config file
KConfigGroup config( KSharedConfig::openConfig(), "General" );
bool autostartSet = config.hasKey( "Autostart" );
bool autostart = config.readEntry( "Autostart", true );
bool alarmsEnabled = config.readEntry( "Enabled", true );
mName = i18nc( "@title:window", "KOrganizer Reminder Daemon" );
setToolTipTitle( mName );
setToolTipIconByName( QLatin1String("korgac") );
// Set up icons
KIconLoader::global()->addAppDir( QLatin1String("korgac") );
KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
QString iconPath = KIconLoader::global()->iconPath( QLatin1String("korgac"), KIconLoader::Panel );
QIcon iconEnabled = QIcon( iconPath );
if ( iconEnabled.isNull() ) {
KMessageBox::sorry( associatedWidget(),
i18nc( "@info", "Cannot load system tray icon." ) );
} else {
KIconLoader loader;
QImage iconDisabled =
iconEnabled.pixmap( loader.currentSize( KIconLoader::Panel ) ).toImage();
KIconEffect::toGray( iconDisabled, 1.0 );
mIconDisabled = QIcon( QPixmap::fromImage( iconDisabled ) );
}
changeSystrayIcon( alarmsEnabled );
// Set up the context menu
mSuspendAll =
contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
SLOT(slotSuspendAll()) );
mDismissAll =
contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
SLOT(slotDismissAll()) );
mSuspendAll->setEnabled( false );
mDismissAll->setEnabled( false );
contextMenu()->addSeparator();
mAlarmsEnabled =
contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
connect(mAlarmsEnabled, &QAction::toggled, this, &AlarmDockWindow::toggleAlarmsEnabled);
mAlarmsEnabled->setCheckable( true );
mAutostart =
contextMenu()->addAction( i18nc( "@action:inmenu", "Start Reminder Daemon at Login" ) );
connect(mAutostart, &QAction::toggled, this, &AlarmDockWindow::toggleAutostart);
mAutostart->setCheckable( true );
mAlarmsEnabled->setChecked( alarmsEnabled );
mAutostart->setChecked( autostart );
// Disable standard quit behaviour. We have to intercept the quit even,
// if the main window is hidden.
// Read the autostart status from the config file
KConfigGroup config(KSharedConfig::openConfig(), "General");
bool autostartSet = config.hasKey("Autostart");
bool autostart = config.readEntry("Autostart", true);
bool alarmsEnabled = config.readEntry("Enabled", true);
mName = i18nc("@title:window", "KOrganizer Reminder Daemon");
setToolTipTitle(mName);
setToolTipIconByName(QLatin1String("korgac"));
// Set up icons
KIconLoader::global()->addAppDir(QLatin1String("korgac"));
KIconLoader::global()->addAppDir(QLatin1String("kdepim"));
QString iconPath = KIconLoader::global()->iconPath(QLatin1String("korgac"), KIconLoader::Panel);
QIcon iconEnabled = QIcon(iconPath);
if (iconEnabled.isNull()) {
KMessageBox::sorry(associatedWidget(),
i18nc("@info", "Cannot load system tray icon."));
} else {
KIconLoader loader;
QImage iconDisabled =
iconEnabled.pixmap(loader.currentSize(KIconLoader::Panel)).toImage();
KIconEffect::toGray(iconDisabled, 1.0);
mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled));
}
changeSystrayIcon(alarmsEnabled);
// Set up the context menu
mSuspendAll =
contextMenu()->addAction(i18nc("@action:inmenu", "Suspend All Reminders"), this,
SLOT(slotSuspendAll()));
mDismissAll =
contextMenu()->addAction(i18nc("@action:inmenu", "Dismiss All Reminders"), this,
SLOT(slotDismissAll()));
mSuspendAll->setEnabled(false);
mDismissAll->setEnabled(false);
contextMenu()->addSeparator();
mAlarmsEnabled =
contextMenu()->addAction(i18nc("@action:inmenu", "Enable Reminders"));
connect(mAlarmsEnabled, &QAction::toggled, this, &AlarmDockWindow::toggleAlarmsEnabled);
mAlarmsEnabled->setCheckable(true);
mAutostart =
contextMenu()->addAction(i18nc("@action:inmenu", "Start Reminder Daemon at Login"));
connect(mAutostart, &QAction::toggled, this, &AlarmDockWindow::toggleAutostart);
mAutostart->setCheckable(true);
mAlarmsEnabled->setChecked(alarmsEnabled);
mAutostart->setChecked(autostart);
// Disable standard quit behaviour. We have to intercept the quit even,
// if the main window is hidden.
#if 0 //QT5
KActionCollection *ac = actionCollection();
const char *quitName = KStandardAction::name( KStandardAction::Quit );
QAction *quit = ac->action( QLatin1String(quitName) );
if ( !quit ) {
qDebug() << "No Quit standard action.";
} else {
quit->disconnect( SIGNAL(triggered(bool)), this, SLOT(maybeQuit()) );
connect(quit, &QAction::activated, this, &AlarmDockWindow::slotQuit);
}
KActionCollection *ac = actionCollection();
const char *quitName = KStandardAction::name(KStandardAction::Quit);
QAction *quit = ac->action(QLatin1String(quitName));
if (!quit) {
qDebug() << "No Quit standard action.";
} else {
quit->disconnect(SIGNAL(triggered(bool)), this, SLOT(maybeQuit()));
connect(quit, &QAction::activated, this, &AlarmDockWindow::slotQuit);
}
#endif
mAutostartSet = autostartSet;
mAutostartSet = autostartSet;
}
AlarmDockWindow::~AlarmDockWindow()
{
}
void AlarmDockWindow::slotUpdate( int reminders )
void AlarmDockWindow::slotUpdate(int reminders)
{
bool actif = ( reminders > 0 );
mSuspendAll->setEnabled( actif );
mDismissAll->setEnabled( actif );
if ( actif ) {
setToolTip( QLatin1String("korgac"), mName, i18ncp( "@info:status",
"There is 1 active reminder.",
"There are %1 active reminders.", reminders ) );
} else {
setToolTip( QLatin1String("korgac"), mName, i18nc( "@info:status", "No active reminders." ) );
}
bool actif = (reminders > 0);
mSuspendAll->setEnabled(actif);
mDismissAll->setEnabled(actif);
if (actif) {
setToolTip(QLatin1String("korgac"), mName, i18ncp("@info:status",
"There is 1 active reminder.",
"There are %1 active reminders.", reminders));
} else {
setToolTip(QLatin1String("korgac"), mName, i18nc("@info:status", "No active reminders."));
}
}
void AlarmDockWindow::toggleAlarmsEnabled( bool checked )
void AlarmDockWindow::toggleAlarmsEnabled(bool checked)
{
changeSystrayIcon( checked );
changeSystrayIcon(checked);
KConfigGroup config( KSharedConfig::openConfig(), "General" );
config.writeEntry( "Enabled", checked );
config.sync();
KConfigGroup config(KSharedConfig::openConfig(), "General");
config.writeEntry("Enabled", checked);
config.sync();
}
void AlarmDockWindow::toggleAutostart( bool checked )
void AlarmDockWindow::toggleAutostart(bool checked)
{
qDebug();
mAutostartSet = true;
enableAutostart( checked );
qDebug();
mAutostartSet = true;
enableAutostart(checked);
}
void AlarmDockWindow::slotSuspendAll()
{
emit suspendAllSignal();
emit suspendAllSignal();
}
void AlarmDockWindow::slotDismissAll()
{
emit dismissAllSignal();
emit dismissAllSignal();
}
void AlarmDockWindow::enableAutostart( bool enable )
void AlarmDockWindow::enableAutostart(bool enable)
{
KConfigGroup config( KSharedConfig::openConfig(), "General" );
config.writeEntry( "Autostart", enable );
config.sync();
KConfigGroup config(KSharedConfig::openConfig(), "General");
config.writeEntry("Autostart", enable);
config.sync();
}
void AlarmDockWindow::activate( const QPoint &pos )
void AlarmDockWindow::activate(const QPoint &pos)
{
Q_UNUSED( pos );
KToolInvocation::startServiceByDesktopName( QLatin1String("korganizer"), QString() );
Q_UNUSED(pos);
KToolInvocation::startServiceByDesktopName(QLatin1String("korganizer"), QString());
}
void AlarmDockWindow::slotQuit()
{
if ( mAutostartSet == true ) {
int result = KMessageBox::warningContinueCancel(
associatedWidget(),
xi18nc( "@info",
"Do you want to quit the KOrganizer reminder daemon?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>" ),
i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
KStandardGuiItem::quit() );
if ( result == KMessageBox::Continue ) {
emit quitSignal();
if (mAutostartSet == true) {
int result = KMessageBox::warningContinueCancel(
associatedWidget(),
xi18nc("@info",
"Do you want to quit the KOrganizer reminder daemon?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>"),
i18nc("@title:window", "Close KOrganizer Reminder Daemon"),
KStandardGuiItem::quit());
if (result == KMessageBox::Continue) {
emit quitSignal();
}
} else {
int result = KMessageBox::questionYesNoCancel(
associatedWidget(),
xi18nc("@info",
"Do you want to start the KOrganizer reminder daemon at login?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>"),
i18nc("@title:window", "Close KOrganizer Reminder Daemon"),
KGuiItem(i18nc("@action:button start the reminder daemon", "Start")),
KGuiItem(i18nc("@action:button do not start the reminder daemon", "Do Not Start")),
KStandardGuiItem::cancel(),
QString::fromLatin1("AskForStartAtLogin"));
bool autostart = true;
if (result == KMessageBox::No) {
autostart = false;
}
enableAutostart(autostart);
if (result != KMessageBox::Cancel) {
emit quitSignal();
}
}
} else {
int result = KMessageBox::questionYesNoCancel(
associatedWidget(),
xi18nc( "@info",
"Do you want to start the KOrganizer reminder daemon at login?<nl/>"
"<note> you will not get calendar reminders unless the daemon is running.</note>" ),
i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
KGuiItem( i18nc( "@action:button start the reminder daemon", "Start" ) ),
KGuiItem( i18nc( "@action:button do not start the reminder daemon", "Do Not Start" ) ),
KStandardGuiItem::cancel(),
QString::fromLatin1( "AskForStartAtLogin" ) );
bool autostart = true;
if ( result == KMessageBox::No ) {
autostart = false;
}
enableAutostart( autostart );
if ( result != KMessageBox::Cancel ) {
emit quitSignal();
}
}
}
void AlarmDockWindow::changeSystrayIcon( bool alarmsEnabled )
void AlarmDockWindow::changeSystrayIcon(bool alarmsEnabled)
{
if ( alarmsEnabled ) {
setIconByName( QLatin1String("korgac") );
} else {
setIconByPixmap( mIconDisabled.pixmap( 22, 22 ) );
}
if (alarmsEnabled) {
setIconByName(QLatin1String("korgac"));
} else {
setIconByPixmap(mIconDisabled.pixmap(22, 22));
}
}
......@@ -32,31 +32,31 @@
class AlarmDockWindow : public KStatusNotifierItem
{
Q_OBJECT
public:
Q_OBJECT
public:
AlarmDockWindow();
virtual ~AlarmDockWindow();
void enableAutostart( bool enabled );
void enableAutostart(bool enabled);
public slots:
void toggleAlarmsEnabled( bool checked );
void toggleAutostart( bool checked );
void slotUpdate( int reminders );
public slots:
void toggleAlarmsEnabled(bool checked);
void toggleAutostart(bool checked);
void slotUpdate(int reminders);
signals:
signals:
void quitSignal();
void suspendAllSignal();
void dismissAllSignal();
protected slots:
virtual void activate( const QPoint &pos );
protected slots:
virtual void activate(const QPoint &pos);
void slotQuit();
void slotSuspendAll();
void slotDismissAll();
private:
void changeSystrayIcon( bool alarmsEnabled );
private:
void changeSystrayIcon(bool alarmsEnabled);
QIcon mIconDisabled;
QString mName;
......
......@@ -55,276 +55,276 @@
#include <QStandardPaths>
#endif
#include <QDebug>
#include <QDebug>
#include "koalarmclient_debug.h"
using namespace KCalCore;
KOAlarmClient::KOAlarmClient( QObject *parent )
: QObject( parent ), mDocker( 0 ), mDialog( 0 )
KOAlarmClient::KOAlarmClient(QObject *parent)
: QObject(parent), mDocker(0), mDialog(0)
{
new KOrgacAdaptor( this );
Akonadi::DBusConnectionPool::threadConnection().registerObject( QLatin1String("/ac"), this );
qDebug();
new KOrgacAdaptor(this);
Akonadi::DBusConnectionPool::threadConnection().registerObject(QLatin1String("/ac"), this);
qDebug();
#if !defined(KORGAC_AKONADI_AGENT)
if ( dockerEnabled() ) {
mDocker = new AlarmDockWindow;
connect(this, &KOAlarmClient::reminderCount, mDocker, &AlarmDockWindow::slotUpdate);
connect(mDocker, &AlarmDockWindow::quitSignal, this, &KOAlarmClient::slotQuit);
}
if (dockerEnabled()) {
mDocker = new AlarmDockWindow;
connect(this, &KOAlarmClient::reminderCount, mDocker, &AlarmDockWindow::slotUpdate);
connect(mDocker, &AlarmDockWindow::quitSignal, this, &KOAlarmClient::slotQuit);
}
#endif
QStringList mimeTypes;
mimeTypes << Event::eventMimeType() << Todo::todoMimeType();
mCalendar = Akonadi::ETMCalendar::Ptr( new Akonadi::ETMCalendar( mimeTypes ) );
mCalendar->setObjectName( QLatin1String("KOrgac's calendar") );
mETM = mCalendar->entityTreeModel();
connect(&mCheckTimer, &QTimer::timeout, this, &KOAlarmClient::checkAlarms);
connect( mETM, SIGNAL(collectionPopulated(Akonadi::Collection::Id)),
SLOT(deferredInit()) );
connect( mETM, SIGNAL(collectionTreeFetched(Akonadi::Collection::List)),
SLOT(deferredInit()) );
KConfigGroup alarmGroup( KSharedConfig::openConfig(), "Alarms" );
const int interval = alarmGroup.readEntry( "Interval", 60 );
qDebug() << "KOAlarmClient check interval:" << interval << "seconds.";
mLastChecked = alarmGroup.readEntry( "CalendarsLastChecked", QDateTime() );
checkAlarms();
mCheckTimer.start( 1000 * interval ); // interval in seconds
connect(qApp, &QApplication::commitDataRequest, this, &KOAlarmClient::slotCommitData);
QStringList mimeTypes;
mimeTypes << Event::eventMimeType() << Todo::todoMimeType();
mCalendar = Akonadi::ETMCalendar::Ptr(new Akonadi::ETMCalendar(mimeTypes));
mCalendar->setObjectName(QLatin1String("KOrgac's calendar"));
mETM = mCalendar->entityTreeModel();
connect(&mCheckTimer, &QTimer::timeout, this, &KOAlarmClient::checkAlarms);
connect(mETM, SIGNAL(collectionPopulated(Akonadi::Collection::Id)),
SLOT(deferredInit()));
connect(mETM, SIGNAL(collectionTreeFetched(Akonadi::Collection::List)),
SLOT(deferredInit()));
KConfigGroup alarmGroup(KSharedConfig::openConfig(), "Alarms");
const int interval = alarmGroup.readEntry("Interval", 60);
qDebug() << "KOAlarmClient check interval:" << interval << "seconds.";
mLastChecked = alarmGroup.readEntry("CalendarsLastChecked", QDateTime());
checkAlarms();
mCheckTimer.start(1000 * interval); // interval in seconds
connect(qApp, &QApplication::commitDataRequest, this, &KOAlarmClient::slotCommitData);
}
KOAlarmClient::~KOAlarmClient()
{
#if !defined(KORGAC_AKONADI_AGENT)
delete mDocker;
delete mDialog;
delete mDocker;
delete mDialog;
#endif
}
void checkAllItems( KCheckableProxyModel *model, const QModelIndex &parent = QModelIndex() )
void checkAllItems(KCheckableProxyModel *model, const QModelIndex &parent = QModelIndex())
{
const int rowCount = model->rowCount( parent );
for ( int row = 0; row < rowCount; row++ ) {
QModelIndex index = model->index( row, 0, parent );
model->setData( index, Qt::Checked, Qt::CheckStateRole );
if ( model->rowCount( index ) > 0 ) {
checkAllItems( model, index );
const int rowCount = model->rowCount(parent);
for (int row = 0; row < rowCount; row++) {
QModelIndex index = model->index(row, 0, parent);
model->setData(index, Qt::Checked, Qt::CheckStateRole);
if (model->rowCount(index) > 0) {
checkAllItems(model, index);
}
}
}
}
void KOAlarmClient::deferredInit()
{
if ( !collectionsAvailable() ) {
return;
}
qCDebug(KOALARMCLIENT_LOG) << "Performing delayed initialization.";
// load reminders that were active when quitting
KConfigGroup genGroup( KSharedConfig::openConfig(), "General" );
const int numReminders = genGroup.readEntry( "Reminders", 0 );
for ( int i=1; i<=numReminders; ++i ) {
const QString group( QString::fromLatin1( "Incidence-%1" ).arg( i ) );
const KConfigGroup incGroup( KSharedConfig::openConfig(), group );
const QUrl url = incGroup.readEntry( "AkonadiUrl" );
Akonadi::Item::Id akonadiItemId = -1;
if ( !url.isValid() ) {
// logic to migrate old KOrganizer incidence uid's to a Akonadi item.
const QString uid = incGroup.readEntry( "UID" );
if ( !uid.isEmpty() ) {
akonadiItemId = mCalendar->item( uid ).id();
}
} else {