Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
KAlarm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PIM
KAlarm
Commits
f6170b29
Commit
f6170b29
authored
Jan 08, 2002
by
David Jarvie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tidying up
svn path=/trunk/kdepim/; revision=130668
parent
5e061e07
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
147 additions
and
321 deletions
+147
-321
kalarmapp.cpp
kalarmapp.cpp
+70
-235
kalarmapp.h
kalarmapp.h
+21
-36
mainwindow.cpp
mainwindow.cpp
+11
-9
mainwindow.h
mainwindow.h
+1
-1
messagewin.cpp
messagewin.cpp
+5
-3
messagewin.h
messagewin.h
+2
-2
prefdlg.cpp
prefdlg.cpp
+3
-5
prefs.cpp
prefs.cpp
+6
-6
prefs.h
prefs.h
+3
-3
prefsettings.cpp
prefsettings.cpp
+3
-2
prefsettings.h
prefsettings.h
+1
-1
traydcop.cpp
traydcop.cpp
+1
-0
traywindow.cpp
traywindow.cpp
+17
-15
traywindow.h
traywindow.h
+3
-3
No files found.
kalarmapp.cpp
View file @
f6170b29
/*
* kalarmapp.cpp -
description
* kalarmapp.cpp -
the KAlarm application object
* Program: kalarm
* (C) 2001, 2002 by David Jarvie software@astrojar.org.uk
*
...
...
@@ -32,27 +32,24 @@
#include <kstddirs.h>
#include <kconfig.h>
#include <kaboutdata.h>
#include <kio/netaccess.h>
#include <kfileitem.h>
#include <ktempfile.h>
#include <dcopclient.h>
#include <kprocess.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kdebug.h>
#include <libkcal/vcaldrag.h>
#include <libkcal/vcalformat.h>
#include <libkcal/icalformat.h>
#include <kalarmd/clientinfo.h>
#include "alarmcalendar.h"
#include "mainwindow.h"
#include "messagewin.h"
#include "traydcop.h"
#include "traywindow.h"
#include "prefsettings.h"
#include "prefdlg.h"
#include "kalarmapp.h"
#include "kalarmapp.moc"
const
QString
DEFAULT_CALENDAR_FILE
(
QString
::
fromLatin1
(
"calendar.ics"
));
const
char
*
DCOP_OBJECT_NAME
=
"display"
;
const
char
*
TRAY_DCOP_OBJECT_NAME
=
"tray"
;
const
char
*
DAEMON_APP_NAME
=
"kalarmd"
;
...
...
@@ -67,23 +64,28 @@ int KAlarmApp::activeCount = 0;
*/
KAlarmApp
::
KAlarmApp
()
:
KUniqueApplication
(),
d
copHandler
(
0L
),
mD
copHandler
(
0L
),
mTrayDcopHandler
(
0L
),
mTrayWindow
(
0L
),
daemonRegistered
(
false
),
mCalendar
(
new
AlarmCalendar
),
mDaemonRegistered
(
false
),
mSettings
(
new
Settings
(
0L
))
{
mSettings
->
loadSettings
();
CalFormat
::
setApplication
(
aboutData
()
->
programName
(),
QString
::
fromLatin1
(
"-//K Desktop Environment//NONSGML %1 "
VERSION
"//EN"
)
.
arg
(
aboutData
()
->
programName
()));
// Set up actions used by more than one menu
mActionPrefs
=
KStdAction
::
preferences
(
this
,
SLOT
(
slotPreferences
()));
mActionDaemonPrefs
=
new
KAction
(
i18n
(
"Configure Alarm &Daemon..."
),
mActionPrefs
->
iconSet
(),
0
,
this
,
SLOT
(
slotDaemonPreferences
()));
}
/******************************************************************************
*/
KAlarmApp
::~
KAlarmApp
()
{
calendar
.
close
();
mCalendar
->
close
();
}
/******************************************************************************
...
...
@@ -106,7 +108,7 @@ int KAlarmApp::newInstance()
kdDebug
(
5950
)
<<
"KAlarmApp::newInstance(): New instance
\n
"
;
++
activeCount
;
static
bool
restored
=
false
;
int
exitCode
=
0
;
// default = success
int
exitCode
=
0
;
// default = success
QString
usage
;
if
(
!
restored
&&
isRestored
())
{
...
...
@@ -189,7 +191,7 @@ int KAlarmApp::newInstance()
if
(
args
->
isSet
(
"calendarURL"
))
{
QString
calendarUrl
=
args
->
getOption
(
"calendarURL"
);
if
(
KURL
(
calendarUrl
).
url
()
!=
calendar
.
urlString
())
if
(
KURL
(
calendarUrl
).
url
()
!=
mCalendar
->
urlString
())
{
usage
=
i18n
(
"--calendarURL: wrong calendar file"
);
break
;
...
...
@@ -340,6 +342,8 @@ int KAlarmApp::newInstance()
std
::
cerr
<<
usage
<<
i18n
(
"
\n
Use --help to get a list of available command line options.
\n
"
);
exitCode
=
1
;
}
--
activeCount
;
// 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.
...
...
@@ -352,11 +356,9 @@ int KAlarmApp::newInstance()
*/
void
KAlarmApp
::
quitIf
(
int
exitCode
)
{
if
(
--
activeCount
<=
0
&&
mainWindowList
.
isEmpty
()
&&
!
MessageWin
::
instanceCount
()
&&
!
mTrayWindow
)
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
);
}
}
...
...
@@ -412,6 +414,35 @@ void KAlarmApp::displayTrayIcon(bool show)
delete
mTrayWindow
;
}
/******************************************************************************
* Activate a new instance of KAlarm.
*/
void
KAlarmApp
::
slotKAlarm
()
{
KProcess
proc
;
proc
<<
QString
::
fromLatin1
(
aboutData
()
->
appName
());
proc
.
start
(
KProcess
::
DontCare
);
}
/******************************************************************************
* Called when a Preferences menu item is selected.
*/
void
KAlarmApp
::
slotPreferences
()
{
(
new
KAlarmPrefDlg
(
settings
()))
->
exec
();
}
/******************************************************************************
* Called when a Configure Daemon menu item is selected.
* Displays the alarm daemon configuration dialog.
*/
void
KAlarmApp
::
slotDaemonPreferences
()
{
KProcess
proc
;
proc
<<
QString
::
fromLatin1
(
"kcmshell"
)
<<
QString
::
fromLatin1
(
"alarmdaemonctrl"
);
proc
.
start
(
KProcess
::
DontCare
);
}
/******************************************************************************
* Called in response to a DCOP notification by the alarm daemon that a new
* message should be scheduled.
...
...
@@ -454,7 +485,7 @@ bool KAlarmApp::scheduleMessage(const QString& message, const QDateTime* dateTim
void
KAlarmApp
::
handleMessage
(
const
QString
&
urlString
,
const
QString
&
eventID
,
EventFunc
function
)
{
kdDebug
(
5950
)
<<
"KAlarmApp::handleMessage(DCOP): "
<<
eventID
<<
endl
;
if
(
KURL
(
urlString
).
url
()
!=
calendar
.
urlString
())
if
(
KURL
(
urlString
).
url
()
!=
mCalendar
->
urlString
())
kdError
(
5950
)
<<
"KAlarmApp::handleMessage(DCOP): wrong calendar file "
<<
urlString
<<
endl
;
else
handleMessage
(
eventID
,
function
);
...
...
@@ -471,7 +502,7 @@ void KAlarmApp::handleMessage(const QString& urlString, const QString& eventID,
bool
KAlarmApp
::
handleMessage
(
const
QString
&
eventID
,
EventFunc
function
)
{
kdDebug
(
5950
)
<<
"KAlarmApp::handleMessage(): "
<<
eventID
<<
", "
<<
(
function
==
EVENT_DISPLAY
?
"DISPLAY"
:
function
==
EVENT_CANCEL
?
"CANCEL"
:
function
==
EVENT_HANDLE
?
"HANDLE"
:
"?"
)
<<
endl
;
Event
*
kcalEvent
=
calendar
.
getEvent
(
eventID
);
Event
*
kcalEvent
=
mCalendar
->
getEvent
(
eventID
);
if
(
!
kcalEvent
)
{
kdError
(
5950
)
<<
"KAlarmApp::handleMessage(): event ID not found: "
<<
eventID
<<
endl
;
...
...
@@ -568,7 +599,7 @@ bool KAlarmApp::handleMessage(const QString& eventID, EventFunc function)
void
KAlarmApp
::
rescheduleAlarm
(
KAlarmEvent
&
event
,
int
alarmID
)
{
kdDebug
(
5950
)
<<
"KAlarmApp::rescheduleAlarm(): "
<<
event
.
id
()
<<
":"
<<
alarmID
<<
endl
;
Event
*
kcalEvent
=
calendar
.
getEvent
(
event
.
id
());
Event
*
kcalEvent
=
mCalendar
->
getEvent
(
event
.
id
());
if
(
!
kcalEvent
)
kdError
(
5950
)
<<
"KAlarmApp::rescheduleAlarm(): event ID not found: "
<<
event
.
id
()
<<
endl
;
else
...
...
@@ -657,8 +688,8 @@ void KAlarmApp::addMessage(const KAlarmEvent& event, KAlarmMainWindow* win)
kdDebug
(
5950
)
<<
"KAlarmApp::addMessage(): "
<<
event
.
id
()
<<
endl
;
// Save the message details in the calendar file, and get the new event ID
calendar
.
addEvent
(
event
);
calendar
.
save
();
mCalendar
->
addEvent
(
event
);
mCalendar
->
save
();
// Tell the daemon to reread the calendar file
reloadDaemon
();
...
...
@@ -680,9 +711,9 @@ void KAlarmApp::modifyMessage(const QString& oldEventID, const KAlarmEvent& newE
kdDebug
(
5950
)
<<
"KAlarmApp::modifyMessage(): '"
<<
oldEventID
<<
endl
;
// Update the event in the calendar file, and get the new event ID
calendar
.
deleteEvent
(
oldEventID
);
calendar
.
addEvent
(
newEvent
);
calendar
.
save
();
mCalendar
->
deleteEvent
(
oldEventID
);
mCalendar
->
addEvent
(
newEvent
);
mCalendar
->
save
();
// Tell the daemon to reread the calendar file
reloadDaemon
();
...
...
@@ -705,8 +736,8 @@ void KAlarmApp::updateMessage(const KAlarmEvent& event, KAlarmMainWindow* win)
// Update the event in the calendar file
const_cast
<
KAlarmEvent
&>
(
event
).
incrementRevision
();
calendar
.
updateEvent
(
event
);
calendar
.
save
();
mCalendar
->
updateEvent
(
event
);
mCalendar
->
save
();
// Tell the daemon to reread the calendar file
reloadDaemon
();
...
...
@@ -732,8 +763,8 @@ void KAlarmApp::deleteMessage(KAlarmEvent& event, KAlarmMainWindow* win, bool te
w
->
deleteMessage
(
event
);
// Delete the event from the calendar file
calendar
.
deleteEvent
(
event
.
id
());
calendar
.
save
();
mCalendar
->
deleteEvent
(
event
.
id
());
mCalendar
->
save
();
// Tell the daemon to reread the calendar file
if
(
tellDaemon
)
...
...
@@ -745,7 +776,7 @@ void KAlarmApp::deleteMessage(KAlarmEvent& event, KAlarmMainWindow* win, bool te
*/
void
KAlarmApp
::
setUpDcop
()
{
dcopHandler
=
new
DcopHandler
(
QString
::
fromLatin1
(
DCOP_OBJECT_NAME
));
mDcopHandler
=
new
DcopHandler
(
QString
::
fromLatin1
(
DCOP_OBJECT_NAME
));
mTrayDcopHandler
=
new
TrayDcopHandler
(
QString
::
fromLatin1
(
TRAY_DCOP_OBJECT_NAME
));
}
...
...
@@ -755,21 +786,21 @@ void KAlarmApp::setUpDcop()
*/
bool
KAlarmApp
::
initCheck
(
bool
calendarOnly
)
{
if
(
!
calendar
.
isOpen
())
if
(
!
mCalendar
->
isOpen
())
{
kdDebug
(
5950
)
<<
"KAlarmApp::initCheck(): opening calendar
\n
"
;
// First time through. Open the calendar file.
if
(
!
calendar
.
open
())
if
(
!
mCalendar
->
open
())
return
false
;
if
(
!
calendarOnly
)
startDaemon
();
// Make sure the alarm daemon is running
}
else
if
(
!
d
aemonRegistered
)
else
if
(
!
mD
aemonRegistered
)
startDaemon
();
if
(
!
calendarOnly
&&
!
d
copHandler
)
if
(
!
calendarOnly
&&
!
mD
copHandler
)
setUpDcop
();
// we're now ready to handle DCOP calls, so set up handlers
return
true
;
}
...
...
@@ -780,7 +811,7 @@ bool KAlarmApp::initCheck(bool calendarOnly)
void
KAlarmApp
::
startDaemon
()
{
kdDebug
(
5950
)
<<
"KAlarmApp::startDaemon()
\n
"
;
calendar
.
getURL
();
// check that the calendar file name is OK - program exit if not
mCalendar
->
getURL
();
// check that the calendar file name is OK - program exit if not
if
(
!
dcopClient
()
->
isApplicationRegistered
(
DAEMON_APP_NAME
))
{
// Start the alarm daemon. It is a KUniqueApplication, which means that
...
...
@@ -804,12 +835,12 @@ void KAlarmApp::startDaemon()
{
QByteArray
data
;
QDataStream
arg
(
data
,
IO_WriteOnly
);
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
calendar
.
urlString
();
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
mCalendar
->
urlString
();
if
(
!
dcopClient
()
->
send
(
DAEMON_APP_NAME
,
DAEMON_DCOP_OBJECT
,
"addMsgCal(QCString,QString)"
,
data
))
kdDebug
(
5950
)
<<
"KAlarmApp::startDaemon(): addCal dcop send failed"
<<
endl
;
}
d
aemonRegistered
=
true
;
mD
aemonRegistered
=
true
;
kdDebug
(
5950
)
<<
"KAlarmApp::startDaemon(): started daemon"
<<
endl
;
}
...
...
@@ -843,7 +874,7 @@ void KAlarmApp::resetDaemon()
{
QByteArray
data
;
QDataStream
arg
(
data
,
IO_WriteOnly
);
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
calendar
.
urlString
();
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
mCalendar
->
urlString
();
if
(
!
dcopClient
()
->
send
(
DAEMON_APP_NAME
,
DAEMON_DCOP_OBJECT
,
"resetMsgCal(QCString,QString)"
,
data
))
kdDebug
(
5950
)
<<
"KAlarmApp::resetDaemon(): addCal dcop send failed"
<<
endl
;
}
...
...
@@ -856,7 +887,7 @@ void KAlarmApp::reloadDaemon()
{
QByteArray
data
;
QDataStream
arg
(
data
,
IO_WriteOnly
);
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
calendar
.
urlString
();
arg
<<
QCString
(
aboutData
()
->
appName
())
<<
mCalendar
->
urlString
();
if
(
!
dcopClient
()
->
send
(
DAEMON_APP_NAME
,
DAEMON_DCOP_OBJECT
,
"reloadMsgCal(QCString,QString)"
,
data
))
kdDebug
(
5950
)
<<
"KAlarmApp::reloadDaemon(): dcop send failed"
<<
endl
;
}
...
...
@@ -966,202 +997,6 @@ bool KAlarmApp::convWakeTime(const QCString timeParam, QDateTime& dateTime)
}
/******************************************************************************
* Read the calendar file URL from the config file (or use the default).
* If there is an error, the program exits.
*/
void
AlarmCalendar
::
getURL
()
const
{
if
(
!
url
.
isValid
())
{
KConfig
*
config
=
kapp
->
config
();
config
->
setGroup
(
QString
::
fromLatin1
(
"General"
));
*
const_cast
<
KURL
*>
(
&
url
)
=
config
->
readEntry
(
QString
::
fromLatin1
(
"Calendar"
),
locateLocal
(
"appdata"
,
DEFAULT_CALENDAR_FILE
));
if
(
!
url
.
isValid
())
{
kdDebug
(
5950
)
<<
"AlarmCalendar::getURL(): invalid name: "
<<
url
.
prettyURL
()
<<
endl
;
KMessageBox
::
error
(
0L
,
i18n
(
"Invalid calendar file name: %1"
).
arg
(
url
.
prettyURL
()),
kapp
->
aboutData
()
->
programName
());
kapp
->
exit
(
1
);
}
}
}
/******************************************************************************
* Open the calendar file and load it into memory.
*/
bool
AlarmCalendar
::
open
()
{
getURL
();
calendar
=
new
CalendarLocal
;
calendar
->
showDialogs
(
FALSE
);
// Find out whether the calendar is ICal or VCal format
QString
ext
=
url
.
filename
().
right
(
4
);
vCal
=
(
ext
==
QString
::
fromLatin1
(
".vcs"
));
if
(
!
KIO
::
NetAccess
::
exists
(
url
))
{
if
(
!
create
())
// create the calendar file
return
false
;
}
// Load the calendar file
switch
(
load
())
{
case
1
:
break
;
case
0
:
if
(
!
create
()
||
load
()
<=
0
)
return
false
;
case
-
1
:
/* if (!KIO::NetAccess::exists(url))
{
if (!create() || load() <= 0)
return false;
}*/
return
false
;
}
return
true
;
}
/******************************************************************************
* Create a new calendar file.
*/
bool
AlarmCalendar
::
create
()
{
// Create the calendar file
KTempFile
*
tmpFile
=
0L
;
QString
filename
;
if
(
url
.
isLocalFile
())
filename
=
url
.
path
();
else
{
tmpFile
=
new
KTempFile
;
filename
=
tmpFile
->
name
();
}
if
(
!
save
(
filename
))
{
delete
tmpFile
;
return
false
;
}
delete
tmpFile
;
return
true
;
}
/******************************************************************************
* Load the calendar file into memory.
* Reply = 1 if success, -2 if failure, 0 if zero-length file exists.
*/
int
AlarmCalendar
::
load
()
{
getURL
();
kdDebug
(
5950
)
<<
"AlarmCalendar::load(): "
<<
url
.
prettyURL
()
<<
endl
;
QString
tmpFile
;
if
(
!
KIO
::
NetAccess
::
download
(
url
,
tmpFile
))
{
kdError
(
5950
)
<<
"AlarmCalendar::load(): Load failure"
<<
endl
;
KMessageBox
::
error
(
0L
,
i18n
(
"Cannot open calendar:
\n
%1"
).
arg
(
url
.
prettyURL
()),
kapp
->
aboutData
()
->
programName
());
return
-
1
;
}
kdDebug
(
5950
)
<<
"AlarmCalendar::load(): --- Downloaded to "
<<
tmpFile
<<
endl
;
if
(
!
calendar
->
load
(
tmpFile
))
{
// Check if the file is zero length
KIO
::
NetAccess
::
removeTempFile
(
tmpFile
);
KIO
::
UDSEntry
uds
;
KIO
::
NetAccess
::
stat
(
url
,
uds
);
KFileItem
fi
(
uds
,
url
);
if
(
!
fi
.
size
())
return
0
;
// file is zero length
kdDebug
(
5950
)
<<
"AlarmCalendar::load(): Error loading calendar file '"
<<
tmpFile
<<
"'"
<<
endl
;
KMessageBox
::
error
(
0L
,
i18n
(
"Error loading calendar:
\n
%1
\n\n
Please fix or delete the file."
).
arg
(
url
.
prettyURL
()),
kapp
->
aboutData
()
->
programName
());
return
-
1
;
}
if
(
!
localFile
.
isEmpty
())
KIO
::
NetAccess
::
removeTempFile
(
localFile
);
localFile
=
tmpFile
;
return
1
;
}
/******************************************************************************
* Save the calendar from memory to file.
*/
bool
AlarmCalendar
::
save
(
const
QString
&
filename
)
{
kdDebug
(
5950
)
<<
"AlarmCalendar::save(): "
<<
filename
<<
endl
;
CalFormat
*
format
=
(
vCal
?
static_cast
<
CalFormat
*>
(
new
VCalFormat
(
calendar
))
:
static_cast
<
CalFormat
*>
(
new
ICalFormat
(
calendar
)));
bool
success
=
calendar
->
save
(
filename
,
format
);
delete
format
;
if
(
!
success
)
{
kdDebug
(
5950
)
<<
"AlarmCalendar::save(): calendar save failed."
<<
endl
;
return
false
;
}
getURL
();
if
(
!
url
.
isLocalFile
())
{
if
(
!
KIO
::
NetAccess
::
upload
(
filename
,
url
))
{
KMessageBox
::
error
(
0L
,
i18n
(
"Cannot upload calendar to
\n
'%1'"
).
arg
(
url
.
prettyURL
()),
kapp
->
aboutData
()
->
programName
());
return
false
;
}
}
// Tell the alarm daemon to reload the calendar
QByteArray
data
;
QDataStream
arg
(
data
,
IO_WriteOnly
);
arg
<<
QCString
(
kapp
->
aboutData
()
->
appName
())
<<
url
.
url
();
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
;
}
/******************************************************************************
* Delete any temporary file at program exit.
*/
void
AlarmCalendar
::
close
()
{
if
(
!
localFile
.
isEmpty
())
KIO
::
NetAccess
::
removeTempFile
(
localFile
);
}
/******************************************************************************
* Add the specified event to the calendar.
*/
void
AlarmCalendar
::
addEvent
(
const
KAlarmEvent
&
event
)
{
Event
*
kcalEvent
=
new
Event
;
event
.
updateEvent
(
*
kcalEvent
);
calendar
->
addEvent
(
kcalEvent
);
const_cast
<
KAlarmEvent
&>
(
event
).
setEventID
(
kcalEvent
->
VUID
());
}
/******************************************************************************
* Update the specified event in the calendar with its new contents.
* The event retains the same ID.
*/
void
AlarmCalendar
::
updateEvent
(
const
KAlarmEvent
&
event
)
{
Event
*
kcalEvent
=
getEvent
(
event
.
id
());
if
(
kcalEvent
)
event
.
updateEvent
(
*
kcalEvent
);
}
/******************************************************************************
* Delete the specified event from the calendar.
*/
void
AlarmCalendar
::
deleteEvent
(
const
QString
&
eventID
)
{
Event
*
kcalEvent
=
getEvent
(
eventID
);
if
(
kcalEvent
)
calendar
->
deleteEvent
(
kcalEvent
);
}
/******************************************************************************
* This class's function is simply to act as a receiver for DCOP requests.
*/
...
...
kalarmapp.h
View file @
f6170b29
/*
* kalarmapp.h -
description
* kalarmapp.h -
the KAlarm application object
* Program: kalarm
* (C) 2001, 2002 by David Jarvie software@astrojar.org.uk
*
...
...
@@ -21,13 +21,15 @@
#ifndef KALARMAPP_H
#define KALARMAPP_H
class
QDateTime
;
#include <kuniqueapp.h>
#include <kurl.h>
class
KAction
;
#include <libkcal/calendarlocal.h>
#include "msgevent.h"
using
namespace
KCal
;
class
AlarmCalendar
;
class
KAlarmEvent
;
class
KAlarmAlarm
;
class
KAlarmMainWindow
;
class
MessageWin
;
class
TrayWindow
;
...
...
@@ -49,40 +51,14 @@ class DcopHandler : public QWidget, DCOPObject
};
class
AlarmCalendar
{
public:
AlarmCalendar
()
:
calendar
(
0L
)
{
}
bool
open
();
int
load
();
bool
save
()
{
return
save
(
localFile
);
}
void
close
();
Event
*
getEvent
(
const
QString
&
uniqueID
)
{
return
calendar
->
getEvent
(
uniqueID
);
}
QPtrList
<
Event
>
getAllEvents
()
{
return
calendar
->
getAllEvents
();
}
void
addEvent
(
const
KAlarmEvent
&
);
void
updateEvent
(
const
KAlarmEvent
&
);
void
deleteEvent
(
const
QString
&
eventID
);
bool
isOpen
()
const
{
return
!!
calendar
;
}
void
getURL
()
const
;
const
QString
urlString
()
const
{
getURL
();
return
url
.
url
();
}
private:
CalendarLocal
*
calendar
;
KURL
url
;
// URL of calendar file
QString
localFile
;
// local name of calendar file
bool
vCal
;
// true if calendar file is in VCal format
bool
create
();
bool
save
(
const
QString
&
tempFile
);
};
class
KAlarmApp
:
public
KUniqueApplication
{
Q_OBJECT
public:
~
KAlarmApp
();
virtual
int
newInstance
();
static
KAlarmApp
*
getInstance
();
AlarmCalendar
&
getCalendar
()
{
return
c
alendar
;
}
AlarmCalendar
&
getCalendar
()
{
return
*
mC
alendar
;
}
Settings
*
settings
()
{
return
mSettings
;
}
void
addWindow
(
KAlarmMainWindow
*
);
void
addWindow
(
TrayWindow
*
w
)
{
mTrayWindow
=
w
;
}
...
...
@@ -91,6 +67,8 @@ class KAlarmApp : public KUniqueApplication
TrayWindow
*
trayWindow
()
const
{
return
mTrayWindow
;
}
void
displayTrayIcon
(
bool
show
);
bool
trayIconDisplayed
()
const
{
return
!!
mTrayWindow
;
}
KAction
*
actionPreferences
()
const
{
return
mActionPrefs
;
}
KAction
*
actionDaemonPreferences
()
const
{
return
mActionDaemonPrefs
;
}
void
resetDaemon
();
void
addMessage
(
const
KAlarmEvent
&
,
KAlarmMainWindow
*
);
void
modifyMessage
(
const
QString
&
oldEventID
,
const
KAlarmEvent
&
newEvent
,
KAlarmMainWindow
*
);
...
...
@@ -108,8 +86,13 @@ class KAlarmApp : public KUniqueApplication
void
displayMessage
(
const
QString
&
calendarFile
,
const
QString
&
eventID
)
{
handleMessage
(
calendarFile
,
eventID
,
EVENT_DISPLAY
);
}
void
deleteMessage
(
const
QString
&
calendarFile
,
const
QString
&
eventID
)
{
handleMessage
(
calendarFile
,
eventID
,
EVENT_CANCEL
);
}
static
const
int
MAX_LATENESS
=
65
;
// maximum number of seconds late to display a late-cancel alarm
public
slots
:
void
slotKAlarm
();
protected:
KAlarmApp
();
private
slots
:
void
slotPreferences
();
void
slotDaemonPreferences
();
private:
enum
EventFunc
{
EVENT_HANDLE
,
EVENT_DISPLAY
,
EVENT_CANCEL
};
enum
AlarmFunc
{
ALARM_DISPLAY
,
ALARM_CANCEL
,
ALARM_RESCHEDULE
};
...
...
@@ -126,12 +109,14 @@ class KAlarmApp : public KUniqueApplication
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
DcopHandler
*
mDcopHandler
;
// 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
AlarmCalendar
*
mCalendar
;
// the calendar containing all the alarms
KAction
*
mActionPrefs
;
// action to display the preferences dialog
KAction
*
mActionDaemonPrefs
;
// action to display the alarm daemon preferences dialog
bool
mDaemonRegistered
;
// true if we've registered with alarm daemon
Settings
*
mSettings
;
// program preferences
};
...
...
mainwindow.cpp
View file @
f6170b29
...
...
@@ -40,6 +40,7 @@
#include <kdebug.h>
#include "kalarmapp.h"
#include "alarmcalendar.h"
#include "editdlg.h"
#include "prefdlg.h"
#include "prefsettings.h"
...
...
@@ -99,7 +100,6 @@ class AlarmListViewItem : public QListViewItem
KAlarmMainWindow
::
KAlarmMainWindow
()
// : MainWindowBase(0L, 0L, WGroupLeader | WStyle_ContextHelp)
:
MainWindowBase
(
0L
,
0L
,
WGroupLeader
|
WStyle_ContextHelp
|
WDestructiveClose
)
{
kdDebug
(
5950
)
<<
"KAlarmMainWindow::KAlarmMainWindow()
\n
"
;
...
...
@@ -154,7 +154,7 @@ void KAlarmMainWindow::initActions()
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
());
//
KAction* preferences = KStdAction::preferences(this, SLOT(slotPreferences()), actionCollection());
KMenuBar
*
menu
=
menuBar
();
KPopupMenu
*
fileMenu
=
new
KPopupMenu
(
this
);
...
...
@@ -171,7 +171,10 @@ void KAlarmMainWindow::initActions()
connect
(
actionsMenu
,
SIGNAL
(
aboutToShow
()),
this
,
SLOT
(
setTrayIconActionText
()));
KPopupMenu
*
settingsMenu
=
new
KPopupMenu
(
this
);
menu
->
insertItem
(
i18n
(
"&Settings"
),
settingsMenu
);
preferences
->
plug
(
settingsMenu
);
#warning "Remove this code"
// preferences->plug(settingsMenu);
theApp
()
->
actionPreferences
()
->
plug
(
settingsMenu
);
theApp
()
->
actionDaemonPreferences
()
->
plug
(
settingsMenu
);
menu
->
insertItem
(
i18n
(
"&Help"
),
helpMenu
());
actionModify
->
setEnabled
(
false
);
...
...
@@ -305,12 +308,12 @@ void KAlarmMainWindow::slotResetDaemon()
/******************************************************************************
* Called when the Preferences menu item is selected.
*/
void
KAlarmMainWindow
::
slotPreferences
()
/*
void KAlarmMainWindow::slotPreferences()
{
KAlarmPrefDlg* pref = new KAlarmPrefDlg(theApp()->settings());
if
(
pref
->
exec
())
theApp
()
->
settings
()
->
saveSettings
();
}
pref->exec();
}*/
#warning "Remove this code"
/******************************************************************************