Commit 5e061e07 authored by David Jarvie's avatar David Jarvie

Incorporate system tray icon into KAlarm

svn path=/trunk/kdepim/; revision=130477
parent ce73e5c8
......@@ -2,10 +2,15 @@
INCLUDES= -I$(top_srcdir) $(all_includes)
bin_PROGRAMS = kalarm
kalarm_SOURCES = main.cpp kalarmapp.cpp editdlg.cpp msgevent.cpp messagewin.cpp fontcolour.cpp fontchooser.cpp colourcombo.cpp prefsettings.cpp prefs.cpp prefdlg.cpp mainwindow.cpp datetime.cpp spinbox2.cpp
kalarm_SOURCES = main.cpp kalarmapp.cpp editdlg.cpp msgevent.cpp messagewin.cpp \
mainwindowbase.cpp mainwindow.cpp \
prefsettings.cpp prefs.cpp prefdlg.cpp \
traywindow.cpp traydcop.cpp traydcopiface.skel \
fontcolour.cpp fontchooser.cpp colourcombo.cpp datetime.cpp spinbox2.cpp
kalarm_LDFLAGS = $(all_libraries) $(KDE_RPATH)
kalarm_LDADD = $(LIB_KDEUI) $(top_builddir)/libkcal/libkcal.la
kalarm_LDADD = $(LIB_KDEUI) $(top_builddir)/libkcal/libkcal.la $(top_builddir)/kalarmd/libkalarmd.la
noinst_HEADERS = kalarm.h kalarmapp.h mainwindow.h messagewin.h editdlg.h \
mainwindowbase.h traywindow.h traydcop.h traydcopiface.h \
msgevent.h datetime.h fontcolour.h fontchooser.h colourcombo.h \
spinbox2.h prefs.h prefsettings.h prefdlg.h
......
/*
* kalarmapp.cpp - description
* Program: kalarm
* (C) 2001 by David Jarvie software@astrojar.org.uk
* (C) 2001, 2002 by David Jarvie software@astrojar.org.uk
*
* 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
......@@ -20,13 +20,12 @@
#include "kalarm.h"
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <iostream>
#include <qfile.h>
#include <iostream>
#include <kcmdlineargs.h>
#include <kmessagebox.h>
#include <klocale.h>
......@@ -47,14 +46,17 @@
#include "mainwindow.h"
#include "messagewin.h"
#include "traydcop.h"
#include "traywindow.h"
#include "prefsettings.h"
#include "kalarmapp.h"
#include "kalarmapp.moc"
const QString DEFAULT_CALENDAR_FILE(QString::fromLatin1("calendar.ics"));
const char* DCOP_OBJECT_NAME = "display";
const char* DAEMON_NAME = "kalarmd";
const char* DAEMON_DCOP_OBJECT_NAME = "ad";
const char* TRAY_DCOP_OBJECT_NAME = "tray";
const char* DAEMON_APP_NAME = "kalarmd";
const char* DAEMON_DCOP_OBJECT = "ad";
KAlarmApp* KAlarmApp::theInstance = 0L;
int KAlarmApp::activeCount = 0;
......@@ -64,12 +66,14 @@ int KAlarmApp::activeCount = 0;
* Construct the application.
*/
KAlarmApp::KAlarmApp()
: KUniqueApplication(),
mainWidget(0L),
daemonRegistered(false),
m_generalSettings(new GeneralSettings(0L))
: KUniqueApplication(),
dcopHandler(0L),
mTrayDcopHandler(0L),
mTrayWindow(0L),
daemonRegistered(false),
mSettings(new Settings(0L))
{
m_generalSettings->loadSettings();
mSettings->loadSettings();
CalFormat::setApplication(aboutData()->programName(),
QString::fromLatin1("-//K Desktop Environment//NONSGML %1 " VERSION "//EN")
.arg(aboutData()->programName()));
......@@ -118,10 +122,14 @@ int KAlarmApp::newInstance()
}
initCheck(); // register with the alarm daemon
restored = true; // make sure we restore only once
// Display the system tray icon if it is configured to be autostarted
if (settings()->autostartTrayIcon())
displayTrayIcon(true);
}
else
{
mainWidget = new MainWidget(QString::fromLatin1(DCOP_OBJECT_NAME));
setUpDcop(); // we're now ready to handle DCOP calls, so set up handlers
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
// Use a 'do' loop which is executed only once to allow easy error exits.
......@@ -146,6 +154,13 @@ int KAlarmApp::newInstance()
resetDaemon();
}
else
if (args->isSet("tray"))
{
// Display only the system tray icon
args->clear(); // free up memory
displayTrayIcon(true);
}
else
if (args->isSet("handleEvent") || args->isSet("displayEvent") || args->isSet("cancelEvent") || args->isSet("calendarURL"))
{
// Display or delete the message with the specified event ID
......@@ -213,7 +228,7 @@ int KAlarmApp::newInstance()
QDateTime* alarmTime = 0L;
QDateTime wakeup;
QColor bgColour = generalSettings()->defaultBgColour();
QColor bgColour = settings()->defaultBgColour();
int repeatCount = 0;
int repeatInterval = 0;
if (args->isSet("colour"))
......@@ -325,14 +340,25 @@ int KAlarmApp::newInstance()
std::cerr << usage << i18n("\nUse --help to get a list of available command line options.\n");
exitCode = 1;
}
if (--activeCount <= 0 && mainWindowList.isEmpty() && !MessageWin::instanceCount())
// Quit the application if this was the last/only running "instance" of the program.
// Executing 'return' doesn't work very well since the program continues to
// run if no windows were created.
quitIf(exitCode);
return exitCode;
}
/******************************************************************************
* Quit the program if there are no more "instances" running.
*/
void KAlarmApp::quitIf(int exitCode)
{
if (--activeCount <= 0 && mainWindowList.isEmpty() && !MessageWin::instanceCount() && !mTrayWindow)
{
// This was the last/only running "instance" of the program, so exit completely.
// Executing 'return' doesn't work very well since the program continues to
// run if no windows were created.
exit(exitCode);
}
return exitCode;
}
/******************************************************************************
......@@ -360,6 +386,32 @@ void KAlarmApp::deleteWindow(KAlarmMainWindow* win)
}
}
/******************************************************************************
* Called when the system tray main window is closed.
*/
void KAlarmApp::deleteWindow(TrayWindow*)
{
mTrayWindow = 0L;
quitIf();
}
/******************************************************************************
* Display or close the system tray icon.
*/
void KAlarmApp::displayTrayIcon(bool show)
{
if (show)
{
if (!mTrayWindow)
{
mTrayWindow = new TrayWindow;
mTrayWindow->show();
}
}
else
delete mTrayWindow;
}
/******************************************************************************
* Called in response to a DCOP notification by the alarm daemon that a new
* message should be scheduled.
......@@ -688,6 +740,15 @@ void KAlarmApp::deleteMessage(KAlarmEvent& event, KAlarmMainWindow* win, bool te
reloadDaemon();
}
/******************************************************************************
* Set up the DCOP handlers.
*/
void KAlarmApp::setUpDcop()
{
dcopHandler = new DcopHandler(QString::fromLatin1(DCOP_OBJECT_NAME));
mTrayDcopHandler = new TrayDcopHandler(QString::fromLatin1(TRAY_DCOP_OBJECT_NAME));
}
/******************************************************************************
* If this is the first time through, open the calendar file, optionally start
* the alarm daemon, and set up the DCOP handler.
......@@ -708,11 +769,8 @@ bool KAlarmApp::initCheck(bool calendarOnly)
else if (!daemonRegistered)
startDaemon();
if (!calendarOnly && !mainWidget)
{
// We're now ready to handle DCOP calls, so set up the handler
mainWidget = new MainWidget(QString::fromLatin1(DCOP_OBJECT_NAME));
}
if (!calendarOnly && !dcopHandler)
setUpDcop(); // we're now ready to handle DCOP calls, so set up handlers
return true;
}
......@@ -723,11 +781,11 @@ void KAlarmApp::startDaemon()
{
kdDebug(5950) << "KAlarmApp::startDaemon()\n";
calendar.getURL(); // check that the calendar file name is OK - program exit if not
if (!dcopClient()->isApplicationRegistered(DAEMON_NAME))
if (!dcopClient()->isApplicationRegistered(DAEMON_APP_NAME))
{
// Start the alarm daemon. It is a KUniqueApplication, which means that
// there is automatically only one instance of the alarm daemon running.
QString execStr = locate("exe",QString::fromLatin1(DAEMON_NAME));
QString execStr = locate("exe",QString::fromLatin1(DAEMON_APP_NAME));
system(QFile::encodeName(execStr));
kdDebug(5950) << "KAlarmApp::startDaemon(): Alarm daemon started" << endl;
}
......@@ -738,7 +796,7 @@ void KAlarmApp::startDaemon()
QDataStream arg(data, IO_WriteOnly);
arg << QCString(aboutData()->appName()) << aboutData()->programName()
<< QCString(DCOP_OBJECT_NAME) << (int)ClientInfo::COMMAND_LINE_NOTIFY << (Q_INT8)0;
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "registerApp(QCString,QString,QCString,int,bool)", data))
if (!dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "registerApp(QCString,QString,QCString,int,bool)", data))
kdDebug(5950) << "KAlarmApp::startDaemon(): registerApp dcop send failed" << endl;
}
......@@ -747,7 +805,7 @@ void KAlarmApp::startDaemon()
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QCString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "addMsgCal(QCString,QString)", data))
if (!dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "addMsgCal(QCString,QString)", data))
kdDebug(5950) << "KAlarmApp::startDaemon(): addCal dcop send failed" << endl;
}
......@@ -761,10 +819,10 @@ void KAlarmApp::startDaemon()
bool KAlarmApp::stopDaemon()
{
kdDebug(5950) << "KAlarmApp::stopDaemon()" << endl;
if (dcopClient()->isApplicationRegistered(DAEMON_NAME))
if (dcopClient()->isApplicationRegistered(DAEMON_APP_NAME))
{
QByteArray data;
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "quit()", data))
if (!dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "quit()", data))
{
kdError(5950) << "KAlarmApp::restartDaemon(): quit dcop send failed" << endl;
return false;
......@@ -779,14 +837,14 @@ bool KAlarmApp::stopDaemon()
void KAlarmApp::resetDaemon()
{
kdDebug(5950) << "KAlarmApp::resetDaemon()" << endl;
if (!dcopClient()->isApplicationRegistered(DAEMON_NAME))
if (!dcopClient()->isApplicationRegistered(DAEMON_APP_NAME))
startDaemon();
else
{
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QCString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "resetMsgCal(QCString,QString)", data))
if (!dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "resetMsgCal(QCString,QString)", data))
kdDebug(5950) << "KAlarmApp::resetDaemon(): addCal dcop send failed" << endl;
}
}
......@@ -799,7 +857,7 @@ void KAlarmApp::reloadDaemon()
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QCString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "reloadMsgCal(QCString,QString)", data))
if (!dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "reloadMsgCal(QCString,QString)", data))
kdDebug(5950) << "KAlarmApp::reloadDaemon(): dcop send failed" << endl;
}
......@@ -1057,7 +1115,7 @@ bool AlarmCalendar::save(const QString& filename)
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QCString(kapp->aboutData()->appName()) << url.url();
if (!kapp->dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "reloadMsgCal(QCString,QString)", data))
if (!kapp->dcopClient()->send(DAEMON_APP_NAME, DAEMON_DCOP_OBJECT, "reloadMsgCal(QCString,QString)", data))
kdDebug(5950) << "AlarmCalendar::save(): addCal dcop send failed" << endl;
return true;
}
......@@ -1107,19 +1165,19 @@ void AlarmCalendar::deleteEvent(const QString& eventID)
/******************************************************************************
* This class's function is simply to act as a receiver for DCOP requests.
*/
MainWidget::MainWidget(const char* dcopObject)
DcopHandler::DcopHandler(const char* dcopObject)
: QWidget(),
DCOPObject(dcopObject)
{
kdDebug(5950) << "MainWidget::MainWidget()\n";
kdDebug(5950) << "DcopHandler::DcopHandler()\n";
}
/******************************************************************************
* Process a DCOP request.
*/
bool MainWidget::process(const QCString& func, const QByteArray& data, QCString& replyType, QByteArray&)
bool DcopHandler::process(const QCString& func, const QByteArray& data, QCString& replyType, QByteArray&)
{
kdDebug(5950) << "MainWidget::process(): " << func << endl;
kdDebug(5950) << "DcopHandler::process(): " << func << endl;
enum { ERR, HANDLE, CANCEL, DISPLAY, SCHEDULE, SCHEDULE_n, SCHEDULE_FILE, SCHEDULE_FILE_n };
int function;
if (func == "handleEvent(const QString&,const QString&)"
......@@ -1145,7 +1203,7 @@ bool MainWidget::process(const QCString& func, const QByteArray& data, QCString&
function = SCHEDULE_FILE_n;
else
{
kdDebug(5950) << "MainWidget::process(): unknown DCOP function" << endl;
kdDebug(5950) << "DcopHandler::process(): unknown DCOP function" << endl;
return false;
}
......
/*
* kalarmapp.h - description
* Program: kalarm
* (C) 2001 by David Jarvie software@astrojar.org.uk
* (C) 2001, 2002 by David Jarvie software@astrojar.org.uk
*
* 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
......@@ -30,15 +30,21 @@ using namespace KCal;
class KAlarmMainWindow;
class MessageWin;
class GeneralSettings;
class TrayWindow;
class TrayDcopHandler;
class Settings;
extern const char* DAEMON_APP_NAME;
extern const char* DAEMON_DCOP_OBJECT;
extern const char* TRAY_DCOP_OBJECT_NAME;
class MainWidget : public QWidget, DCOPObject
class DcopHandler : public QWidget, DCOPObject
{
Q_OBJECT
public:
MainWidget(const char* name);
~MainWidget() { }
DcopHandler(const char* name);
~DcopHandler() { }
virtual bool process(const QCString& func, const QByteArray& data, QCString& replyType, QByteArray& replyData);
};
......@@ -77,9 +83,14 @@ class KAlarmApp : public KUniqueApplication
virtual int newInstance();
static KAlarmApp* getInstance();
AlarmCalendar& getCalendar() { return calendar; }
GeneralSettings* generalSettings() { return m_generalSettings; }
Settings* settings() { return mSettings; }
void addWindow(KAlarmMainWindow*);
void addWindow(TrayWindow* w) { mTrayWindow = w; }
void deleteWindow(KAlarmMainWindow*);
void deleteWindow(TrayWindow*);
TrayWindow* trayWindow() const { return mTrayWindow; }
void displayTrayIcon(bool show);
bool trayIconDisplayed() const { return !!mTrayWindow; }
void resetDaemon();
void addMessage(const KAlarmEvent&, KAlarmMainWindow*);
void modifyMessage(const QString& oldEventID, const KAlarmEvent& newEvent, KAlarmMainWindow*);
......@@ -103,6 +114,8 @@ class KAlarmApp : public KUniqueApplication
enum EventFunc { EVENT_HANDLE, EVENT_DISPLAY, EVENT_CANCEL };
enum AlarmFunc { ALARM_DISPLAY, ALARM_CANCEL, ALARM_RESCHEDULE };
bool initCheck(bool calendarOnly = false);
void quitIf(int exitCode = 0);
void setUpDcop();
bool stopDaemon();
void startDaemon();
void reloadDaemon();
......@@ -111,13 +124,15 @@ class KAlarmApp : public KUniqueApplication
void handleAlarm(KAlarmEvent&, KAlarmAlarm&, AlarmFunc, bool updateCalAndDisplay);
static bool convWakeTime(const QCString timeParam, QDateTime&);
static KAlarmApp* theInstance;
static int activeCount; // number of active instances without main windows
MainWidget* mainWidget; // the parent of the DCOP receiver object
QPtrList<KAlarmMainWindow> mainWindowList; // active main windows
AlarmCalendar calendar;
bool daemonRegistered; // true if we've registered with alarm daemon
GeneralSettings* m_generalSettings; // general program preferences
static KAlarmApp* theInstance; // the one and only KAlarmApp instance
static int activeCount; // number of active instances without main windows
DcopHandler* dcopHandler; // the parent of the main DCOP receiver object
TrayDcopHandler* mTrayDcopHandler; // the parent of the system tray DCOP receiver object
QPtrList<KAlarmMainWindow> mainWindowList; // active main windows
TrayWindow* mTrayWindow; // active system tray icon
AlarmCalendar calendar; // the calendar containing all the alarms
bool daemonRegistered; // true if we've registered with alarm daemon
Settings* mSettings; // program preferences
};
inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
......
/*
* mainwindow.cpp - main application window
* Program: kalarm
* (C) 2001 by David Jarvie software@astrojar.org.uk
* (C) 2001, 2002 by David Jarvie software@astrojar.org.uk
*
* 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
......@@ -28,12 +28,15 @@
#include <kmenubar.h>
#include <kpopupmenu.h>
#include <kaccel.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kconfig.h>
#include <kaboutdata.h>
#include <klistview.h>
#include <kdebug.h>
#include "kalarmapp.h"
......@@ -43,10 +46,61 @@
#include "mainwindow.h"
#include "mainwindow.moc"
using namespace std;
class AlarmListViewItem;
struct AlarmItemData
{
KAlarmEvent event;
QString messageText; // message as displayed
QString dateTimeText; // date/time as displayed
QString repeatCountText; // repeat count as displayed
QString repeatCountOrder; // repeat count item ordering text
int messageWidth; // width required to display 'messageText'
};
class AlarmListView : public KListView
{
public:
enum { TIME_COLUMN, REPEAT_COLUMN, COLOUR_COLUMN, MESSAGE_COLUMN };
AlarmListView(QWidget* parent = 0L, const char* name = 0L);
virtual void clear();
void refresh();
AlarmListViewItem* addEntry(const KAlarmEvent&, bool setSize = false);
AlarmListViewItem* updateEntry(AlarmListViewItem*, const KAlarmEvent& newEvent, bool setSize = false);
void deleteEntry(AlarmListViewItem*, bool setSize = false);
const KAlarmEvent getEntry(AlarmListViewItem* item) const { return getData(item)->event; }
AlarmListViewItem* getEntry(const QString& eventID);
const AlarmItemData* getData(AlarmListViewItem*) const;
void resizeLastColumn();
int itemHeight();
bool drawMessageInColour() const { return drawMessageInColour_; }
void setDrawMessageInColour(bool inColour) { drawMessageInColour_ = inColour; }
AlarmListViewItem* selectedItem() const { return (AlarmListViewItem*)KListView::selectedItem(); }
AlarmListViewItem* currentItem() const { return (AlarmListViewItem*)KListView::currentItem(); }
private:
typedef QMap<AlarmListViewItem*, AlarmItemData> EntryMap;
EntryMap entries;
int lastColumnHeaderWidth_;
bool drawMessageInColour_;
};
class AlarmListViewItem : public QListViewItem
{
public:
AlarmListViewItem(QListView* parent, const QString&, const QString&);
virtual void paintCell(QPainter*, const QColorGroup&, int column, int width, int align);
AlarmListView* alarmListView() const { return (AlarmListView*)listView(); }
};
KAlarmMainWindow::KAlarmMainWindow()
: KMainWindow(0L, 0L, WGroupLeader | WStyle_ContextHelp)
// : MainWindowBase(0L, 0L, WGroupLeader | WStyle_ContextHelp)
: MainWindowBase(0L, 0L, WGroupLeader | WStyle_ContextHelp | WDestructiveClose)
{
kdDebug(5950) << "KAlarmMainWindow::KAlarmMainWindow()\n";
setAutoSaveSettings(QString::fromLatin1("MainWindow")); // save window sizes etc.
......@@ -75,7 +129,7 @@ KAlarmMainWindow::~KAlarmMainWindow()
void KAlarmMainWindow::resizeEvent(QResizeEvent* re)
{
listView->resizeLastColumn();
KMainWindow::resizeEvent(re);
MainWindowBase::resizeEvent(re);
}
/******************************************************************************
......@@ -86,7 +140,7 @@ void KAlarmMainWindow::resizeEvent(QResizeEvent* re)
void KAlarmMainWindow::showEvent(QShowEvent* se)
{
listView->resizeLastColumn();
KMainWindow::showEvent(se);
MainWindowBase::showEvent(se);
}
/******************************************************************************
......@@ -94,11 +148,12 @@ void KAlarmMainWindow::showEvent(QShowEvent* se)
*/
void KAlarmMainWindow::initActions()
{
actionQuit = new KAction(i18n("&Quit"), QIconSet(SmallIcon("exit")), KStdAccel::key(KStdAccel::Quit), this, SLOT(slotQuit()), this);
actionNew = new KAction(i18n("&New"), "eventnew", Qt::Key_Insert, this, SLOT(slotNew()), this);
actionModify = new KAction(i18n("&Modify"), "eventmodify", Qt::CTRL+Qt::Key_M, this, SLOT(slotModify()), this);
actionDelete = new KAction(i18n("&Delete"), "eventdelete", Qt::Key_Delete, this, SLOT(slotDelete()), this);
actionResetDaemon = new KAction(i18n("&Reset Daemon"), "reset", Qt::CTRL+Qt::Key_R, this, SLOT(slotResetDaemon()), this);
actionQuit = new KAction(i18n("&Quit"), QIconSet(SmallIcon("exit")), KStdAccel::key(KStdAccel::Quit), this, SLOT(slotQuit()), this);
actionNew = new KAction(i18n("&New"), "eventnew", Qt::Key_Insert, this, SLOT(slotNew()), this);
actionModify = new KAction(i18n("&Modify"), "eventmodify", Qt::CTRL+Qt::Key_M, this, SLOT(slotModify()), this);
actionDelete = new KAction(i18n("&Delete"), "eventdelete", Qt::Key_Delete, this, SLOT(slotDelete()), this);
actionToggleTrayIcon = new KAction(QString(), QIconSet(SmallIcon("kalarm")), Qt::CTRL+Qt::Key_T, this, SLOT(slotToggleTrayIcon()), this);
actionResetDaemon = new KAction(i18n("&Reset Daemon"), "reload", Qt::CTRL+Qt::Key_R, this, SLOT(slotResetDaemon()), this);
KAction* preferences = KStdAction::preferences(this, SLOT(slotPreferences()), actionCollection());
KMenuBar* menu = menuBar();
......@@ -111,7 +166,9 @@ void KAlarmMainWindow::initActions()
actionModify->plug(actionsMenu);
actionDelete->plug(actionsMenu);
actionsMenu->insertSeparator(3);
actionToggleTrayIcon->plug(actionsMenu);
actionResetDaemon->plug(actionsMenu);
connect(actionsMenu, SIGNAL(aboutToShow()), this, SLOT(setTrayIconActionText()));
KPopupMenu* settingsMenu = new KPopupMenu(this);
menu->insertItem(i18n("&Settings"), settingsMenu);
preferences->plug(settingsMenu);
......@@ -166,12 +223,11 @@ void KAlarmMainWindow::deleteMessage(const KAlarmEvent& event)
*/
void KAlarmMainWindow::slotNew()
{
EditAlarmDlg* editDlg = new EditAlarmDlg(i18n("New Message"), this, "editDlg");
EditAlarmDlg* editDlg = new EditAlarmDlg(i18n("New message"), this, "editDlg");
if (editDlg->exec() == QDialog::Accepted)
{
KAlarmEvent event;
editDlg->getEvent(event);
//event->setOrganizer("KAlarm");
// Add the message to the displayed lists and to the calendar file
theApp()->addMessage(event, this);
......@@ -221,6 +277,23 @@ void KAlarmMainWindow::slotDelete()
}
}
/******************************************************************************
* Called when the Display System Tray Icon menu item is selected.
*/
void KAlarmMainWindow::slotToggleTrayIcon()
{
theApp()->displayTrayIcon(!theApp()->trayIconDisplayed());
}
/******************************************************************************
* Set the system tray icon menu text according to whether or not the system
* tray icon is currently visible.
*/
void KAlarmMainWindow::setTrayIconActionText()
{
actionToggleTrayIcon->setText(theApp()->trayIconDisplayed() ? i18n("Hide System &Tray Icon") : i18n("Show System &Tray Icon"));
}
/******************************************************************************
* Called when the Reset Daemon menu item is selected.
*/
......@@ -234,16 +307,9 @@ void KAlarmMainWindow::slotResetDaemon()
*/
void KAlarmMainWindow::slotPreferences()
{
#ifdef MISC_PREFS
KAlarmPrefDlg* pref = new KAlarmPrefDlg(theApp()->generalSettings(), m_miscSettings);
#else
KAlarmPrefDlg* pref = new KAlarmPrefDlg(theApp()->generalSettings());
#endif
KAlarmPrefDlg* pref = new KAlarmPrefDlg(theApp()->settings());
if (pref->exec())
{
theApp()->generalSettings()->saveSettings();
KGlobal::config()->sync();
}
theApp()->settings()->saveSettings();
}
/******************************************************************************
......@@ -346,9 +412,9 @@ void AlarmListView::refresh()
AlarmListViewItem* AlarmListView::getEntry(const QString& eventID)
{
for (map<AlarmListViewItem*, AlarmItemData>::const_iterator it = entries.begin(); it != entries.end(); ++it)
if (it->second.event.id() == eventID)
return it->first;
for (EntryMap::ConstIterator it = entries.begin(); it != entries.end(); ++it)
if (it.data().event.id() == eventID)
return it.key();
return 0L;
}
......@@ -397,10 +463,10 @@ AlarmListViewItem* AlarmListView::updateEntry(AlarmListViewItem* item, const KAl
void AlarmListView::deleteEntry(AlarmListViewItem* item, bool setSize)
{
map<AlarmListViewItem*, AlarmItemData>::iterator it = entries.find(item);
EntryMap::Iterator it = entries.find(item);
if (it != entries.end())
{
entries.erase(it);
entries.remove(it);
delete item;
if (setSize)
resizeLastColumn();
......@@ -409,10 +475,10 @@ void AlarmListView::deleteEntry(AlarmListViewItem* item, bool setSize)
const AlarmItemData* AlarmListView::getData(AlarmListViewItem* item) const
{
map<AlarmListViewItem*, AlarmItemData>::const_iterator it = entries.find(item);
EntryMap::ConstIterator it = entries.find(item);
if (it == entries.end())
return 0L;
return &it->second;
return &it.data();
}
/******************************************************************************
......@@ -422,9 +488,9 @@ const AlarmItemData* AlarmListView::getData(AlarmListViewItem* item) const
void AlarmListView::resizeLastColumn()
{
int messageWidth = lastColumnHeaderWidth_;
for (map<AlarmListViewItem*, AlarmItemData>::const_iterator it = entries.begin(); it != entries.end(); ++it)
for (EntryMap::ConstIterator it = entries.begin(); it != entries.end(); ++it)
{
int mw = it->second.messageWidth;
int mw = it.data().messageWidth;
if (mw > messageWidth)
messageWidth = mw;
}
......@@ -440,7 +506,7 @@ void AlarmListView::resizeLastColumn()
int AlarmListView::itemHeight()
{
map<AlarmListViewItem*, AlarmItemData>::const_iterator it = entries.begin();
EntryMap::ConstIterator it = entries.begin();
if (it == entries.end())
{
// The list is empty, so create a temporary item to find its height
......@@ -450,7 +516,7 @@ int AlarmListView::itemHeight()
return height;
}