Commit 07b3673f authored by David Jarvie's avatar David Jarvie

Convert QPtrList to QValueList (to help migration to Qt4)

svn path=/trunk/KDE/kdepim/; revision=431635
parent 7b8558a7
......@@ -468,10 +468,9 @@ void displayUpdateError(QWidget* parent, UpdateError code, bool multipleAlarms)
* Returns a list of all alarm templates.
* If shell commands are disabled, command alarm templates are omitted.
*/
QPtrList<KAEvent> templateList()
QValueList<KAEvent> templateList()
{
QPtrList<KAEvent> templates;
templates.setAutoDelete(true);
QValueList<KAEvent> templates;
AlarmCalendar* cal = AlarmCalendar::templateCalendarOpen();
if (cal)
{
......@@ -480,8 +479,8 @@ QPtrList<KAEvent> templateList()
for (KCal::Event::List::ConstIterator it = events.begin(); it != events.end(); ++it)
{
KCal::Event* kcalEvent = *it;
KAEvent* event = new KAEvent(*kcalEvent);
if (includeCmdAlarms || event->action() != KAEvent::COMMAND)
KAEvent event(*kcalEvent);
if (includeCmdAlarms || event.action() != KAEvent::COMMAND)
templates.append(event);
}
}
......
......@@ -60,7 +60,7 @@ QString browseFile(const QString& caption, QString& defaultDir, cons
const QString& filter = QString::null, int mode = 0, QWidget* parent = 0, const char* name = 0);
KAction* createNewAlarmAction(const QString& label, QObject* receiver, const char* slot, KActionCollection*, const char* name);
TemplateMenuAction* createNewFromTemplateAction(const QString& label, QObject* receiver, const char* slot, KActionCollection*, const char* name);
QPtrList<KAEvent> templateList();
QValueList<KAEvent> templateList();
void outputAlarmWarnings(QWidget* parent, const KAEvent* = 0);
void resetDaemon();
void resetDaemonIfQueued(); // must only be called from KAlarmApp::processQueue()
......
/*
* kalarmapp.cpp - the KAlarm application object
* Program: kalarm
* (C) 2001 - 2005 by David Jarvie <software@astrojar.org.uk>
* Copyright (C) 2001 - 2005 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
......@@ -110,7 +110,6 @@ KAlarmApp::KAlarmApp()
#if KDE_VERSION < 290
marginKDE2 = KDialog::marginHint();
#endif
mCommandProcesses.setAutoDelete(true);
Preferences* preferences = Preferences::instance();
connect(preferences, SIGNAL(preferencesChanged()), SLOT(slotPreferencesChanged()));
KCal::CalFormat::setApplication(aboutData()->programName(),
......@@ -157,6 +156,12 @@ KAlarmApp::KAlarmApp()
*/
KAlarmApp::~KAlarmApp()
{
while (!mCommandProcesses.isEmpty())
{
ProcData* pd = mCommandProcesses.first();
mCommandProcesses.pop_front();
delete pd;
}
AlarmCalendar::terminateCalendars();
}
......@@ -762,7 +767,7 @@ void KAlarmApp::quitIf(int exitCode, bool force)
if (checkSystemTray())
return;
}
if (mDcopQueue.count() || mCommandProcesses.count())
if (!mDcopQueue.isEmpty() || !mCommandProcesses.isEmpty())
{
// Don't quit yet if there are outstanding actions on the DCOP queue
mPendingQuit = true;
......@@ -878,7 +883,7 @@ void KAlarmApp::processQueue()
KAlarm::resetDaemonIfQueued();
// Process DCOP calls
while (mDcopQueue.count())
while (!mDcopQueue.isEmpty())
{
DcopQEntry& entry = mDcopQueue.first();
if (entry.eventId.isEmpty())
......@@ -1176,7 +1181,7 @@ bool KAlarmApp::scheduleEvent(KAEvent::Action action, const QString& text, const
}
if (!audioFile.isEmpty())
event.setAudioFile(audioFile, audioVolume, -1, 0);
if (mailAddresses.count())
if (!mailAddresses.isEmpty())
event.setEmail(mailFromID, mailAddresses, mailSubject, mailAttachments);
event.setRecurrence(recurrence);
event.setFirstRecurrence();
......@@ -1663,7 +1668,7 @@ void* KAlarmApp::execAlarm(KAEvent& event, const KAAlarm& alarm, bool reschedule
QStringList errmsgs;
if (!KAMail::send(event, errmsgs, (reschedule || allowDefer)))
result = 0;
if (errmsgs.count())
if (!errmsgs.isEmpty())
{
// Some error occurred, although the email may have been sent successfully
if (result)
......@@ -1779,7 +1784,8 @@ ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& e
// Error executing command - report it
kdError(5950) << "KAlarmApp::doShellCommand(): command failed to start\n";
commandErrorMsg(proc, event, alarm, flags);
mCommandProcesses.removeRef(pd);
mCommandProcesses.remove(pd);
delete pd;
return 0;
}
......@@ -1818,8 +1824,9 @@ void KAlarmApp::slotCommandOutput(KProcess* proc, char* buffer, int bufflen)
{
kdDebug(5950) << "KAlarmApp::slotCommandOutput(): '" << QCString(buffer, bufflen+1) << "'\n";
// Find this command in the command list
for (ProcData* pd = mCommandProcesses.first(); pd; pd = mCommandProcesses.next())
for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
{
ProcData* pd = *it;
if (pd->process == proc && pd->logProcess)
{
pd->logProcess->writeStdin(buffer, bufflen);
......@@ -1845,8 +1852,9 @@ void KAlarmApp::slotCommandExited(ShellProcess* proc)
{
kdDebug(5950) << "KAlarmApp::slotCommandExited()\n";
// Find this command in the command list
for (ProcData* pd = mCommandProcesses.first(); pd; pd = mCommandProcesses.next())
for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
{
ProcData* pd = *it;
if (pd->process == proc)
{
// Found the command
......@@ -1877,12 +1885,14 @@ void KAlarmApp::slotCommandExited(ShellProcess* proc)
}
if (pd->preAction())
execAlarm(*pd->event, *pd->alarm, pd->reschedule(), pd->allowDefer(), true);
mCommandProcesses.remove();
mCommandProcesses.remove(it);
delete pd;
break;
}
}
// Now that there are no executing shell commands, quit if a quit was queued
if (mPendingQuit && !mCommandProcesses.count())
// If there are now no executing shell commands, quit if a quit was queued
if (mPendingQuit && mCommandProcesses.isEmpty())
quitIf(mPendingQuitCode);
}
......@@ -1908,8 +1918,9 @@ void KAlarmApp::commandErrorMsg(const ShellProcess* proc, const KAEvent& event,
void KAlarmApp::commandMessage(ShellProcess* proc, QWidget* parent)
{
// Find this command in the command list
for (ProcData* pd = mCommandProcesses.first(); pd; pd = mCommandProcesses.next())
for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
{
ProcData* pd = *it;
if (pd->process == proc)
{
pd->messageBoxParent = parent;
......@@ -2133,7 +2144,7 @@ static bool convInterval(QCString timeParam, KAEvent::RecurType& recurType, int&
KAlarmApp::ProcData::~ProcData()
{
while (tempFiles.count())
while (!tempFiles.isEmpty())
{
// Delete the temporary file called by the XTerm command
QFile f(tempFiles.first());
......
/*
* kalarmapp.h - the KAlarm application object
* Program: kalarm
* (C) 2001 - 2005 by David Jarvie <software@astrojar.org.uk>
* Copyright (C) 2001 - 2005 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
......@@ -21,6 +21,8 @@
#ifndef KALARMAPP_H
#define KALARMAPP_H
/** @file kalarmapp.h - the KAlarm application object */
#include <qguardedptr.h>
class QTimer;
class QDateTime;
......@@ -168,7 +170,7 @@ class KAlarmApp : public KUniqueApplication
QTime mStartOfDay; // start-of-day time currently in use
QColor mPrefsExpiredColour; // expired alarms text colour
int mPrefsExpiredKeepDays;// how long expired alarms are being kept
QPtrList<ProcData> mCommandProcesses; // currently active command alarm processes
QValueList<ProcData*> mCommandProcesses; // currently active command alarm processes
QValueList<DcopQEntry> mDcopQueue; // DCOP command queue
int mPendingQuitCode; // exit code for a pending quit
bool mPendingQuit; // quit once the DCOP command and shell command queues have been processed
......
......@@ -63,7 +63,6 @@
#include "templatepickdlg.h"
#include "templatedlg.h"
#include "traywindow.h"
#include "mainwindow.h"
#include "mainwindow.moc"
using namespace KCal;
......@@ -83,8 +82,8 @@ KShortcut redoShortcut;
= Class: MainWindow
=============================================================================*/
QPtrList<MainWindow> MainWindow::mWindowList;
TemplateDlg* MainWindow::mTemplateDlg = 0;
MainWindow::WindowList MainWindow::mWindowList;
TemplateDlg* MainWindow::mTemplateDlg = 0;
// Collect these widget labels together to ensure consistent wording and
// translations across different modules.
......@@ -161,8 +160,7 @@ MainWindow::MainWindow(bool restored)
MainWindow::~MainWindow()
{
kdDebug(5950) << "MainWindow::~MainWindow()\n";
if (findWindow(this))
mWindowList.remove();
mWindowList.remove(this);
if (theApp()->trayWindow())
{
if (isTrayParent())
......@@ -215,9 +213,9 @@ MainWindow* MainWindow::mainMainWindow()
MainWindow* tray = theApp()->trayWindow() ? theApp()->trayWindow()->assocMainWindow() : 0;
if (tray && tray->isVisible())
return tray;
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
if (w->isVisible())
return w;
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
if ((*it)->isVisible())
return *it;
if (tray)
return tray;
return mWindowList.first();
......@@ -237,7 +235,7 @@ bool MainWindow::isTrayParent() const
void MainWindow::closeAll()
{
while (mWindowList.first())
delete mWindowList.first();
delete mWindowList.first(); // N.B. the destructor removes the window from the list
}
/******************************************************************************
......@@ -390,8 +388,8 @@ void MainWindow::initActions()
*/
void MainWindow::enableTemplateMenuItem(bool enable)
{
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
w->mActionTemplates->setEnabled(enable);
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
(*it)->mActionTemplates->setEnabled(enable);
}
/******************************************************************************
......@@ -400,8 +398,8 @@ void MainWindow::enableTemplateMenuItem(bool enable)
void MainWindow::refresh()
{
kdDebug(5950) << "MainWindow::refresh()\n";
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
w->mListView->refresh();
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
(*it)->mListView->refresh();
}
/******************************************************************************
......@@ -413,8 +411,9 @@ void MainWindow::updateExpired()
{
kdDebug(5950) << "MainWindow::updateExpired()\n";
bool enableShowExpired = Preferences::instance()->expiredKeepDays();
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
{
MainWindow* w = *it;
if (w->mShowExpired)
{
if (!enableShowExpired)
......@@ -443,8 +442,9 @@ void MainWindow::updateTimeColumns(bool oldTime, bool oldTimeTo)
oldTime = true; // at least one time column must have been displayed
if (newTime != oldTime || newTimeTo != oldTimeTo)
{
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
{
MainWindow* w = *it;
if (w->mShowTime == oldTime
&& w->mShowTimeTo == oldTimeTo)
{
......@@ -469,8 +469,9 @@ void MainWindow::setUpdateTimer()
// Check whether any windows need to be updated
MainWindow* needTimer = 0;
MainWindow* timerWindow = 0;
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
{
MainWindow* w = *it;
if (w->isVisible() && w->mListView->showingTimeTo())
needTimer = w;
if (w->mMinuteTimerActive)
......@@ -498,9 +499,12 @@ void MainWindow::setUpdateTimer()
void MainWindow::slotUpdateTimeTo()
{
kdDebug(5950) << "MainWindow::slotUpdateTimeTo()" << endl;
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
for (WindowList::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
{
MainWindow* w = *it;
if (w->isVisible() && w->mListView->showingTimeTo())
w->mListView->updateTimeToAlarms();
}
}
/******************************************************************************
......@@ -1272,7 +1276,7 @@ void MainWindow::setEnableText(bool enable)
*/
MainWindow* MainWindow::toggleWindow(MainWindow* win)
{
if (win && findWindow(win))
if (win && mWindowList.find(win) != mWindowList.end())
{
// A window is specified (and it exists)
if (win->isVisible())
......@@ -1297,14 +1301,3 @@ MainWindow* MainWindow::toggleWindow(MainWindow* win)
win->show();
return win;
}
/******************************************************************************
* Find the specified window in the main window list.
*/
bool MainWindow::findWindow(MainWindow* win)
{
for (MainWindow* w = mWindowList.first(); w; w = mWindowList.next())
if (w == win)
return true;
return false;
}
/*
* mainwindow.h - main application window
* Program: kalarm
* (C) 2001 - 2005 by David Jarvie <software@astrojar.org.uk>
* Copyright (C) 2001 - 2005 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
......@@ -21,6 +21,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
/** @file mainwindow.h - main application window */
#include "alarmevent.h"
#include "alarmtext.h"
#include "mainwindowbase.h"
......@@ -128,6 +130,8 @@ class MainWindow : public MainWindowBase
void updateActionsMenu();
private:
typedef QValueList<MainWindow*> WindowList;
MainWindow(bool restored);
void createListView(bool recreate);
void initActions();
......@@ -137,10 +141,9 @@ class MainWindow : public MainWindowBase
static void initUndoMenu(KPopupMenu*, Undo::Type);
static void setUpdateTimer();
static void enableTemplateMenuItem(bool);
static bool findWindow(MainWindow*);
static QPtrList<MainWindow> mWindowList; // active main windows
static TemplateDlg* mTemplateDlg; // the one and only template dialogue
static WindowList mWindowList; // active main windows
static TemplateDlg* mTemplateDlg; // the one and only template dialogue
AlarmListView* mListView;
KAction* mActionTemplates;
......
......@@ -126,7 +126,7 @@ class MWMimeSourceFactory : public QMimeSourceFactory
static const Qt::WFlags WFLAGS = Qt::WStyle_StaysOnTop | Qt::WDestructiveClose;
QPtrList<MessageWin> MessageWin::mWindowList;
QValueList<MessageWin*> MessageWin::mWindowList;
/******************************************************************************
......@@ -256,12 +256,7 @@ MessageWin::~MessageWin()
stopPlay();
delete mWinModule;
mWinModule = 0;
for (MessageWin* w = mWindowList.first(); w; w = mWindowList.next())
if (w == this)
{
mWindowList.remove();
break;
}
mWindowList.remove(this);
if (!mRecreating)
{
if (!mNoPostAction && !mEvent.postAction().isEmpty())
......@@ -740,9 +735,12 @@ void MessageWin::readProperties(KConfig* config)
*/
MessageWin* MessageWin::findEvent(const QString& eventID)
{
for (MessageWin* w = mWindowList.first(); w; w = mWindowList.next())
for (QValueList<MessageWin*>::Iterator it = mWindowList.begin(); it != mWindowList.end(); ++it)
{
MessageWin* w = *it;
if (w->mEventID == eventID && !w->mErrorWindow)
return w;
}
return 0;
}
......
......@@ -21,6 +21,8 @@
#ifndef MESSAGEWIN_H
#define MESSAGEWIN_H
/** @file messagewin.h - displays an alarm message */
#include "mainwindowbase.h"
#include "alarmevent.h"
......@@ -92,7 +94,7 @@ class MessageWin : public MainWindowBase
void playAudio();
void setDeferralLimit(const KAEvent&);
static QPtrList<MessageWin> mWindowList; // list of existing message windows
static QValueList<MessageWin*> mWindowList; // list of existing message windows
// Properties needed by readProperties()
QString mMessage;
QFont mFont;
......
/*
* templatelistview.cpp - widget showing list of alarm templates
* Program: kalarm
* (C) 2004, 2005 by David Jarvie <software@astrojar.org.uk>
* Copyright (C) 2004, 2005 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
......@@ -61,9 +61,9 @@ TemplateListView::~TemplateListView()
*/
void TemplateListView::populate()
{
QPtrList<KAEvent> templates = KAlarm::templateList();
for (KAEvent* e = templates.first(); e; e = templates.next())
addEntry(*e);
QValueList<KAEvent> templates = KAlarm::templateList();
for (QValueList<KAEvent>::Iterator it = templates.begin(); it != templates.end(); ++it)
addEntry(*it);
}
/******************************************************************************
......
/*
* templatemenuaction.cpp - menu action to select a template
* Program: kalarm
* (C) 2005 by David Jarvie <software@astrojar.org.uk>
* Copyright (C) 2005 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
......@@ -48,9 +48,9 @@ void TemplateMenuAction::slotInitMenu()
{
KPopupMenu* menu = popupMenu();
menu->clear();
QPtrList<KAEvent> templates = KAlarm::templateList();
for (KAEvent* e = templates.first(); e; e = templates.next())
menu->insertItem(e->templateName());
QValueList<KAEvent> templates = KAlarm::templateList();
for (QValueList<KAEvent>::Iterator it = templates.begin(); it != templates.end(); ++it)
menu->insertItem((*it).templateName());
}
/******************************************************************************
......
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