Commit 88cbf2a1 authored by David Jarvie's avatar David Jarvie

Bugfixes and minor polishing

svn path=/trunk/kdepim/; revision=125067
parent 08e72349
......@@ -7,6 +7,15 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "kalarm.h"
......@@ -298,12 +307,8 @@ void EditAlarmDlg::slotOk()
{
// Convert any relative file path to absolute
// (using home directory as the default)
int i = 0;
alarmMessage = messageEdit->text();
if (alarmMessage.startsWith(QString::fromLatin1("file:/")))
alarmMessage = alarmMessage.mid(5);
else
i = alarmMessage.find(QString::fromLatin1("/"));
int i = alarmMessage.find(QString::fromLatin1("/"));
if (i > 0 && alarmMessage[i - 1] == ':')
{
KURL url(alarmMessage);
......@@ -327,6 +332,7 @@ void EditAlarmDlg::slotOk()
i18n("Continue")) == Cancel)
return;
}
alarmMessage = QString::fromLatin1("file:") + alarmMessage;
}
}
else
......@@ -355,8 +361,6 @@ void EditAlarmDlg::slotBrowse()
if (!url.isEmpty())
{
alarmMessage = url.prettyURL();
if (alarmMessage.startsWith(QString::fromLatin1("file:/")))
alarmMessage = alarmMessage.mid(5);
messageEdit->setText(alarmMessage);
defaultDir = url.path();
}
......
/*
* kalarmapp.cpp - description
* Program: kalarm
*
* (C) 2001 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
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "kalarm.h"
......@@ -20,6 +28,7 @@
#include <klocale.h>
#include <kstddirs.h>
#include <kconfig.h>
#include <kaboutdata.h>
#include <kio/netaccess.h>
#include <kfileitem.h>
#include <ktempfile.h>
......@@ -38,6 +47,8 @@
const QString DCOP_OBJECT_NAME(QString::fromLatin1("display"));
const QString DEFAULT_CALENDAR_FILE(QString::fromLatin1("calendar.ics"));
const char* DAEMON_NAME = "kalarmd";
const char* DAEMON_DCOP_OBJECT_NAME = "ad";
KAlarmApp* KAlarmApp::theInstance = 0L;
......@@ -53,7 +64,9 @@ KAlarmApp::KAlarmApp()
m_generalSettings(new GeneralSettings(0L))
{
m_generalSettings->loadSettings();
CalFormat::setApplication(PROGRAM_TITLE, "-//K Desktop Environment//NONSGML " PROGRAM_TITLE " " VERSION "//EN");
CalFormat::setApplication(aboutData()->programName(),
QString::fromLatin1("-//K Desktop Environment//NONSGML %1 " VERSION "//EN")
.arg(aboutData()->programName()));
}
/******************************************************************************
......@@ -263,7 +276,7 @@ int KAlarmApp::newInstance()
else
{
// No arguments - run interactively & display the dialogue
KAlarmMainWindow* mainWindow = new KAlarmMainWindow(PROGRAM_TITLE);
KAlarmMainWindow* mainWindow = new KAlarmMainWindow;
mainWindow->show();
}
}
......@@ -661,11 +674,11 @@ void KAlarmApp::startDaemon()
{
kdDebug() << "KAlarmApp::startDaemon()\n";
calendar.getURL(); // check that the calendar file name is OK - program exit if not
if (!dcopClient()->isApplicationRegistered("kalarmd"))
if (!dcopClient()->isApplicationRegistered(DAEMON_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("kalarmd"));
QString execStr = locate("exe",QString::fromLatin1(DAEMON_NAME));
system(execStr.latin1());
kdDebug() << "KAlarmApp::startDaemon(): Alarm daemon started" << endl;
}
......@@ -674,8 +687,8 @@ void KAlarmApp::startDaemon()
{
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QString(PROGRAM_NAME) << QString(PROGRAM_TITLE) << DCOP_OBJECT_NAME << (Q_INT8)1 << (Q_INT8)0;
if (!dcopClient()->send("kalarmd","ad","registerApp(QString,QString,QString,bool,bool)", data))
arg << QString(aboutData()->appName()) << aboutData()->programName() << DCOP_OBJECT_NAME << (Q_INT8)1 << (Q_INT8)0;
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "registerApp(QString,QString,QString,bool,bool)", data))
kdDebug() << "KAlarmApp::startDaemon(): registerApp dcop send failed" << endl;
}
......@@ -683,8 +696,8 @@ void KAlarmApp::startDaemon()
{
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QString(PROGRAM_NAME) << calendar.urlString();
if (!dcopClient()->send("kalarmd","ad","addMsgCal(QString,QString)", data))
arg << QString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "addMsgCal(QString,QString)", data))
kdDebug() << "KAlarmApp::startDaemon(): addCal dcop send failed" << endl;
}
......@@ -698,10 +711,10 @@ void KAlarmApp::startDaemon()
bool KAlarmApp::stopDaemon()
{
kdDebug() << "KAlarmApp::stopDaemon()" << endl;
if (dcopClient()->isApplicationRegistered("kalarmd"))
if (dcopClient()->isApplicationRegistered(DAEMON_NAME))
{
QByteArray data;
if (!dcopClient()->send("kalarmd","ad","quit()", data))
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "quit()", data))
{
kdError() << "KAlarmApp::restartDaemon(): quit dcop send failed" << endl;
return false;
......@@ -716,14 +729,14 @@ bool KAlarmApp::stopDaemon()
void KAlarmApp::resetDaemon()
{
kdDebug() << "KAlarmApp::resetDaemon()" << endl;
if (!dcopClient()->isApplicationRegistered("kalarmd"))
if (!dcopClient()->isApplicationRegistered(DAEMON_NAME))
startDaemon();
else
{
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QString(PROGRAM_NAME) << calendar.urlString();
if (!dcopClient()->send("kalarmd","ad","resetMsgCal(QString,QString)", data))
arg << QString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "resetMsgCal(QString,QString)", data))
kdDebug() << "KAlarmApp::resetDaemon(): addCal dcop send failed" << endl;
}
}
......@@ -735,8 +748,8 @@ void KAlarmApp::reloadDaemon()
{
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QString(PROGRAM_NAME) << calendar.urlString();
if (!kapp->dcopClient()->send("kalarmd","ad","reloadMsgCal(QString,QString)", data))
arg << QString(aboutData()->appName()) << calendar.urlString();
if (!dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "reloadMsgCal(QString,QString)", data))
kdDebug() << "KAlarmApp::reloadDaemon(): dcop send failed" << endl;
}
......@@ -860,7 +873,8 @@ void AlarmCalendar::getURL() const
if (!url.isValid())
{
kdDebug() << "AlarmCalendar::getURL(): invalid name: " << url.prettyURL() << endl;
KMessageBox::error(0L, i18n("Invalid calendar file name: %1").arg(url.prettyURL()), PROGRAM_TITLE);
KMessageBox::error(0L, i18n("Invalid calendar file name: %1").arg(url.prettyURL()),
kapp->aboutData()->programName());
kapp->exit(1);
}
}
......@@ -940,7 +954,7 @@ int AlarmCalendar::load()
if (!KIO::NetAccess::download(url, tmpFile))
{
kdError() << "AlarmCalendar::load(): Load failure" << endl;
KMessageBox::error(0L, i18n("Cannot open calendar:\n%1").arg(url.prettyURL()), PROGRAM_TITLE);
KMessageBox::error(0L, i18n("Cannot open calendar:\n%1").arg(url.prettyURL()), kapp->aboutData()->programName());
return -1;
}
kdDebug() << "AlarmCalendar::load(): --- Downloaded to " << tmpFile << endl;
......@@ -954,7 +968,8 @@ int AlarmCalendar::load()
if (!fi.size())
return 0; // file is zero length
kdDebug() << "AlarmCalendar::load(): Error loading calendar file '" << tmpFile << "'" << endl;
KMessageBox::error(0L, i18n("Error loading calendar:\n%1\n\nPlease fix or delete the file.").arg(url.prettyURL()), PROGRAM_TITLE);
KMessageBox::error(0L, i18n("Error loading calendar:\n%1\n\nPlease fix or delete the file.").arg(url.prettyURL()),
kapp->aboutData()->programName());
return -1;
}
if (!localFile.isEmpty())
......@@ -983,7 +998,7 @@ bool AlarmCalendar::save(const QString& filename)
{
if (!KIO::NetAccess::upload(filename, url))
{
KMessageBox::error(0L, i18n("Cannot upload calendar to\n'%1'").arg(url.prettyURL()), PROGRAM_TITLE);
KMessageBox::error(0L, i18n("Cannot upload calendar to\n'%1'").arg(url.prettyURL()), kapp->aboutData()->programName());
return false;
}
}
......@@ -991,8 +1006,8 @@ bool AlarmCalendar::save(const QString& filename)
// Tell the alarm daemon to reload the calendar
QByteArray data;
QDataStream arg(data, IO_WriteOnly);
arg << QString(PROGRAM_NAME) << url.url();
if (!kapp->dcopClient()->send("kalarmd","ad","reloadMsgCal(QString,QString)", data))
arg << QString(kapp->aboutData()->appName()) << url.url();
if (!kapp->dcopClient()->send(DAEMON_NAME, DAEMON_DCOP_OBJECT_NAME, "reloadMsgCal(QString,QString)", data))
kdDebug() << "AlarmCalendar::save(): addCal dcop send failed" << endl;
return true;
}
......
/*
* kalarmapp.h - description
* Program: kalarm
*
* (C) 2001 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
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef KALARMAPP_H
......
/*
* main.cpp
* Program: kalarm
*
* (C) 2001 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
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "kalarm.h"
......@@ -21,6 +29,7 @@
#include "kalarmapp.h"
#define PROGRAM_NAME "kalarm"
static KCmdLineOptions options[] =
{
......@@ -54,7 +63,7 @@ static KCmdLineOptions options[] =
int main(int argc, char *argv[])
{
KAboutData aboutData(PROGRAM_NAME, I18N_NOOP(PROGRAM_TITLE),
KAboutData aboutData(PROGRAM_NAME, I18N_NOOP("KAlarm"),
VERSION, I18N_NOOP(" " PROGRAM_NAME "\n"
" " PROGRAM_NAME " -f[bcilLrt]\n"
" " PROGRAM_NAME " [-bcilLrt] message\n"
......
/*
* mainwindow.cpp - main application window
* Program: kalarm
*
* (C) 2001 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "kalarm.h"
......@@ -25,6 +33,7 @@
#include <kmessagebox.h>
#include <klocale.h>
#include <kconfig.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include "kalarmapp.h"
......@@ -35,12 +44,12 @@
#include "mainwindow.moc"
KAlarmMainWindow::KAlarmMainWindow(const char* name)
: KMainWindow(0L, name, WGroupLeader)
KAlarmMainWindow::KAlarmMainWindow()
: KMainWindow(0L, 0L, WGroupLeader | WStyle_ContextHelp)
{
kdDebug() << "KAlarmMainWindow::KAlarmMainWindow()\n";
setAutoSaveSettings(QString::fromLatin1("MainWindow")); // save window sizes etc.
setPlainCaption(name);
setPlainCaption(kapp->aboutData()->programName());
initActions();
listView = new AlarmListView(this, "listView");
......@@ -501,18 +510,20 @@ void AlarmListViewItem::paintCell(QPainter* painter, const QColorGroup& cg, int
=============================================================================*/
QString AlarmListWhatsThis::text(const QPoint& pt)
{
if (listView->header()->frameGeometry().contains(pt))
QRect frame = listView->header()->frameGeometry();
if (frame.contains(pt)
|| listView->itemAt(QPoint(listView->itemMargin(), pt.y())) && frame.contains(QPoint(pt.x(), frame.y())))
{
switch (listView->header()->sectionAt(pt.x()))
{
case AlarmListView::TIME_COLUMN: return i18n("Next scheduled date and time of the alarm");
case AlarmListView::COLOUR_COLUMN: return i18n("Background colour of alarm message");
case AlarmListView::MESSAGE_COLUMN: return i18n("Alarm message text");
case AlarmListView::MESSAGE_COLUMN: return i18n("Alarm message text or URL of text file to display");
case AlarmListView::REPEAT_COLUMN:
return i18n("Number of scheduled repetitions after the\n"
"next scheduled display of the alarm.\n"
"'%1' indicates that the alarm is repeated\n"
"at every login").arg(repeatAtLoginIndicator);
"at every login.").arg(repeatAtLoginIndicator);
}
}
return i18n("List of scheduled alarm messages");
......
......@@ -8,6 +8,15 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef MAINWINDOW_H
......@@ -35,7 +44,7 @@ class KAlarmMainWindow : public KMainWindow
Q_OBJECT
public:
KAlarmMainWindow(const char* name = 0L);
KAlarmMainWindow();
~KAlarmMainWindow();
void addMessage(const KAlarmEvent&);
......
/*
* messagewin.cpp - displays an alarm message
* Program: kalarm
*
* (C) 2001 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "kalarm.h"
......@@ -21,6 +29,7 @@
#include <qwhatsthis.h>
#include <kstddirs.h>
#include <kaboutdata.h>
#include <klocale.h>
#include <kconfig.h>
#include <kiconloader.h>
......@@ -49,7 +58,7 @@ static const int MAX_LINE_LENGTH = 80; // maximum width (in characters) to tr
* displayed.
*/
MessageWin::MessageWin(const KAlarmEvent& evnt, const KAlarmAlarm& alarm, bool reschedule_event)
: KMainWindow(0L, "MessageWin", WStyle_StaysOnTop | WDestructiveClose | WGroupLeader),
: KMainWindow(0L, "MessageWin", WStyle_StaysOnTop | WDestructiveClose | WGroupLeader | WStyle_ContextHelp),
event(evnt),
message(alarm.messageIsFileName() ? alarm.fileName() : alarm.message()),
font(theApp()->generalSettings()->messageFont()),
......@@ -132,8 +141,7 @@ QSize MessageWin::initView()
bool opened = false;
bool dir = false;
QString tmpFile;
KURL url; // don't use KURL(message) since a UNIX file path may not initialise correctly
url.setPath(message);
KURL url(message);
if (KIO::NetAccess::download(url, tmpFile))
{
QFile qfile(tmpFile);
......@@ -163,6 +171,7 @@ QSize MessageWin::initView()
// So there is no need to calculate an accurate size.
int h = fm.lineSpacing() * (n <= 20 ? n : 20) + 2*view->frameWidth();
view->resize(QSize(h, h).expandedTo(view->sizeHint()));
QWhatsThis::add(view, i18n("The contents of the file to be displayed"));
}
KIO::NetAccess::removeTempFile(tmpFile);
}
......@@ -186,6 +195,7 @@ QSize MessageWin::initView()
label->setFont(font);
label->setPalette(QPalette(colour, colour));
label->setFixedSize(label->sizeHint());
QWhatsThis::add(label, i18n("The alarm message"));
int spacing = label->fontMetrics().lineSpacing()/2 - KDialog::spacingHint();
topLayout->addSpacing(spacing);
topLayout->addWidget(label);
......@@ -217,7 +227,7 @@ QSize MessageWin::initView()
// KAlarm button
KIconLoader iconLoader;
QPixmap pixmap = iconLoader.loadIcon(QString::fromLatin1(PROGRAM_NAME), KIcon::MainToolbar);
QPixmap pixmap = iconLoader.loadIcon(QString::fromLatin1(kapp->aboutData()->appName()), KIcon::MainToolbar);
QPushButton* button = new QPushButton(topWidget);
button->setPixmap(pixmap);
button->setFixedSize(button->sizeHint());
......@@ -427,6 +437,6 @@ void MessageWin::slotDefer()
void MessageWin::slotKAlarm()
{
KProcess proc;
proc << QString::fromLatin1(PROGRAM_NAME);
proc << QString::fromLatin1(kapp->aboutData()->appName());
proc.start(KProcess::DontCare);
}
/*
* messagewin.h - displays an alarm message
* Program: kalarm
*
* (C) 2001 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef MESSAGEWIN_H
......
......@@ -7,6 +7,15 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
......
/*
* msgevent.h - the event object for messages
* Program: kalarm
*
* (C) 2001 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
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef KALARMEVENT_H
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment