• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kalarm

birthdaydlg.cpp

Go to the documentation of this file.
00001 /*
00002  *  birthdaydlg.cpp  -  dialog to pick birthdays from address book
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include "alarmcalendar.h"
00024 #include "birthdaymodel.h"
00025 #include "checkbox.h"
00026 #include "editdlgtypes.h"
00027 #include "fontcolourbutton.h"
00028 #include "kalarmapp.h"
00029 #include "latecancel.h"
00030 #include "preferences.h"
00031 #include "reminder.h"
00032 #include "repetition.h"
00033 #include "shellprocess.h"
00034 #include "soundpicker.h"
00035 #include "specialactions.h"
00036 #include "birthdaydlg.moc"
00037 
00038 #include <QAction>
00039 #include <QGroupBox>
00040 #include <QLabel>
00041 #include <QTreeView>
00042 #include <QHeaderView>
00043 #include <QHBoxLayout>
00044 #include <QVBoxLayout>
00045 
00046 #include <klocale.h>
00047 #include <kglobal.h>
00048 #include <kconfiggroup.h>
00049 #include <kmessagebox.h>
00050 #include <kstandardaction.h>
00051 #include <kactioncollection.h>
00052 #include <khbox.h>
00053 #include <kdebug.h>
00054 #include <kdeversion.h>
00055 
00056 using namespace KCal;
00057 
00058 
00059 BirthdayDlg::BirthdayDlg(QWidget* parent)
00060     : KDialog(parent),
00061       mSpecialActionsButton(0)
00062 {
00063     setObjectName("BirthdayDlg");    // used by LikeBack
00064     setCaption(i18nc("@title:window", "Import Birthdays From KAddressBook"));
00065     setButtons(Ok | Cancel);
00066     setDefaultButton(Ok);
00067     connect(this, SIGNAL(okClicked()), SLOT(slotOk()));
00068 
00069     QWidget* topWidget = new QWidget(this);
00070     setMainWidget(topWidget);
00071     QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
00072     topLayout->setMargin(0);
00073     topLayout->setSpacing(spacingHint());
00074 
00075     // Prefix and suffix to the name in the alarm text
00076     // Get default prefix and suffix texts from config file
00077     KConfigGroup config(KGlobal::config(), "General");
00078     mPrefixText = config.readEntry("BirthdayPrefix", i18nc("@info/plain", "Birthday: "));
00079     mSuffixText = config.readEntry("BirthdaySuffix");
00080 
00081     QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Alarm Text"), topWidget);
00082     topLayout->addWidget(textGroup);
00083     QGridLayout* grid = new QGridLayout(textGroup);
00084     grid->setMargin(marginHint());
00085     grid->setSpacing(spacingHint());
00086     QLabel* label = new QLabel(i18nc("@label:textbox", "Prefix:"), textGroup);
00087     label->setFixedSize(label->sizeHint());
00088     grid->addWidget(label, 0, 0);
00089     mPrefix = new BLineEdit(mPrefixText, textGroup);
00090     mPrefix->setMinimumSize(mPrefix->sizeHint());
00091     label->setBuddy(mPrefix);
00092     connect(mPrefix, SIGNAL(focusLost()), SLOT(slotTextLostFocus()));
00093     mPrefix->setWhatsThis(i18nc("@info:whatsthis",
00094           "Enter text to appear before the person's name in the alarm message, "
00095           "including any necessary trailing spaces."));
00096     grid->addWidget(mPrefix, 0, 1);
00097 
00098     label = new QLabel(i18nc("@label:textbox", "Suffix:"), textGroup);
00099     label->setFixedSize(label->sizeHint());
00100     grid->addWidget(label, 1, 0);
00101     mSuffix = new BLineEdit(mSuffixText, textGroup);
00102     mSuffix->setMinimumSize(mSuffix->sizeHint());
00103     label->setBuddy(mSuffix);
00104     connect(mSuffix, SIGNAL(focusLost()), SLOT(slotTextLostFocus()));
00105     mSuffix->setWhatsThis(i18nc("@info:whatsthis",
00106           "Enter text to appear after the person's name in the alarm message, "
00107           "including any necessary leading spaces."));
00108     grid->addWidget(mSuffix, 1, 1);
00109 
00110     QGroupBox* group = new QGroupBox(i18nc("@title:group", "Select Birthdays"), topWidget);
00111     topLayout->addWidget(group);
00112     QVBoxLayout* layout = new QVBoxLayout(group);
00113     layout->setMargin(0);
00114     BirthdayModel* model = BirthdayModel::instance(this);
00115     connect(model, SIGNAL(addrBookError()), SLOT(addrBookError()));
00116     connect(model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), SLOT(resizeViewColumns()));
00117     model->setPrefixSuffix(mPrefixText, mSuffixText);
00118     BirthdaySortModel* sortModel = new BirthdaySortModel(model, this);
00119     sortModel->setSortCaseSensitivity(Qt::CaseInsensitive);
00120     mListView = new QTreeView(group);
00121     mListView->setModel(sortModel);
00122     mListView->setRootIsDecorated(false);    // don't show expander icons
00123     mListView->setSortingEnabled(true);
00124     mListView->sortByColumn(BirthdayModel::NameColumn);
00125     mListView->setAllColumnsShowFocus(true);
00126     mListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
00127     mListView->setSelectionBehavior(QAbstractItemView::SelectRows);
00128     mListView->setTextElideMode(Qt::ElideRight);
00129     mListView->header()->setResizeMode(BirthdayModel::NameColumn, QHeaderView::Stretch);
00130     mListView->header()->setResizeMode(BirthdayModel::DateColumn, QHeaderView::ResizeToContents);
00131     connect(mListView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), SLOT(slotSelectionChanged()));
00132     mListView->setWhatsThis(i18nc("@info:whatsthis",
00133           "<para>Select birthdays to set alarms for.<nl/>"
00134           "This list shows all birthdays in <application>KAddressBook</application> except those for which alarms already exist.</para>"
00135           "<para>You can select multiple birthdays at one time by dragging the mouse over the list, "
00136           "or by clicking the mouse while pressing Ctrl or Shift.</para>"));
00137     layout->addWidget(mListView);
00138 
00139     group = new QGroupBox(i18nc("@title:group", "Alarm Configuration"), topWidget);
00140     topLayout->addWidget(group);
00141     QVBoxLayout* groupLayout = new QVBoxLayout(group);
00142     groupLayout->setMargin(marginHint());
00143     groupLayout->setSpacing(spacingHint());
00144 
00145     // Sound checkbox and file selector
00146     QHBoxLayout* hlayout = new QHBoxLayout();
00147     hlayout->setMargin(0);
00148     groupLayout->addLayout(hlayout);
00149     mSoundPicker = new SoundPicker(group);
00150     mSoundPicker->setFixedSize(mSoundPicker->sizeHint());
00151     hlayout->addWidget(mSoundPicker);
00152     hlayout->addSpacing(2*spacingHint());
00153     hlayout->addStretch();
00154 
00155     // Font and colour choice button and sample text
00156     mFontColourButton = new FontColourButton(group);
00157     mFontColourButton->setMaximumHeight(mFontColourButton->sizeHint().height() * 3/2);
00158     hlayout->addWidget(mFontColourButton);
00159     connect(mFontColourButton, SIGNAL(selected(const QColor&, const QColor&)), SLOT(setColours(const QColor&, const QColor&)));
00160 
00161     // How much advance warning to give
00162     mReminder = new Reminder(i18nc("@info:whatsthis", "Check to display a reminder in advance of the birthday."),
00163                              i18nc("@info:whatsthis", "Enter the number of days before each birthday to display a reminder. "
00164                                   "This is in addition to the alarm which is displayed on the birthday."),
00165                              false, false, group);
00166     mReminder->setFixedSize(mReminder->sizeHint());
00167     mReminder->setMaximum(0, 364);
00168     mReminder->setMinutes(0, true);
00169     groupLayout->addWidget(mReminder, 0, Qt::AlignLeft);
00170 
00171     // Acknowledgement confirmation required - default = no confirmation
00172     hlayout = new QHBoxLayout();
00173     hlayout->setMargin(0);
00174     hlayout->setSpacing(2*spacingHint());
00175     groupLayout->addLayout(hlayout);
00176     mConfirmAck = EditDisplayAlarmDlg::createConfirmAckCheckbox(group);
00177     mConfirmAck->setFixedSize(mConfirmAck->sizeHint());
00178     hlayout->addWidget(mConfirmAck);
00179     hlayout->addSpacing(2*spacingHint());
00180     hlayout->addStretch();
00181 
00182     if (ShellProcess::authorised())    // don't display if shell commands not allowed (e.g. kiosk mode)
00183     {
00184         // Special actions button
00185         mSpecialActionsButton = new SpecialActionsButton(false, group);
00186         mSpecialActionsButton->setFixedSize(mSpecialActionsButton->sizeHint());
00187         hlayout->addWidget(mSpecialActionsButton);
00188     }
00189 
00190     // Late display checkbox - default = allow late display
00191     hlayout = new QHBoxLayout();
00192     hlayout->setMargin(0);
00193     hlayout->setSpacing(2*spacingHint());
00194     groupLayout->addLayout(hlayout);
00195     mLateCancel = new LateCancelSelector(false, group);
00196     mLateCancel->setFixedSize(mLateCancel->sizeHint());
00197     hlayout->addWidget(mLateCancel);
00198     hlayout->addStretch();
00199 
00200     // Sub-repetition button
00201     mSubRepetition = new RepetitionButton(i18nc("@action:button", "Sub-Repetition"), false, group);
00202     mSubRepetition->setFixedSize(mSubRepetition->sizeHint());
00203     mSubRepetition->set(0, 0, true, 364*24*60);
00204     mSubRepetition->setWhatsThis(i18nc("@info:whatsthis", "Set up an additional alarm repetition"));
00205     hlayout->addWidget(mSubRepetition);
00206 
00207     // Set the values to their defaults
00208     setColours(Preferences::defaultFgColour(), Preferences::defaultBgColour());
00209     mFontColourButton->setDefaultFont();
00210     mFontColourButton->setBgColour(Preferences::defaultBgColour());
00211     mFontColourButton->setFgColour(Preferences::defaultFgColour());
00212     mLateCancel->setMinutes(Preferences::defaultLateCancel(), true, TimePeriod::Days);
00213     mConfirmAck->setChecked(Preferences::defaultConfirmAck());
00214     mSoundPicker->set(Preferences::defaultSoundType(), Preferences::defaultSoundFile(),
00215                       Preferences::defaultSoundVolume(), -1, 0, Preferences::defaultSoundRepeat());
00216     if (mSpecialActionsButton)
00217         mSpecialActionsButton->setActions(Preferences::defaultPreAction(), Preferences::defaultPostAction(), Preferences::defaultCancelOnPreActionError());
00218 
00219     KActionCollection* actions = new KActionCollection(this);
00220     KStandardAction::selectAll(mListView, SLOT(selectAll()), actions);
00221     KStandardAction::deselect(mListView, SLOT(clearSelection()), actions);
00222     actions->addAssociatedWidget(mListView);
00223     foreach (QAction* action, actions->actions())
00224         action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
00225 
00226     enableButtonOk(false);     // only enable OK button when something is selected
00227 }
00228 
00229 /******************************************************************************
00230 * Display an error message about failure to load address book.
00231 */
00232 void BirthdayDlg::addrBookError()
00233 {
00234     KMessageBox::error(this, i18nc("@info", "Error reading address book"));
00235 }
00236 
00237 /******************************************************************************
00238 * Return a list of events for birthdays chosen.
00239 */
00240 QList<KAEvent> BirthdayDlg::events() const
00241 {
00242     QList<KAEvent> list;
00243     QModelIndexList indexes = mListView->selectionModel()->selectedRows();
00244     int count = indexes.count();
00245     if (!count)
00246         return list;
00247     QDate today = QDate::currentDate();
00248     KDateTime todayStart(today, KDateTime::ClockTime);
00249     int thisYear = today.year();
00250     int reminder = mReminder->minutes();
00251     const BirthdaySortModel* model = static_cast<const BirthdaySortModel*>(indexes[0].model());
00252     for (int i = 0;  i < count;  ++i)
00253     {
00254         BirthdayModel::Data* data = model->rowData(indexes[i]);
00255         if (!data)
00256             continue;
00257         QDate date = data->birthday;
00258         date.setYMD(thisYear, date.month(), date.day());
00259         if (date <= today)
00260             date.setYMD(thisYear + 1, date.month(), date.day());
00261         KAEvent event(KDateTime(date, KDateTime::ClockTime),
00262                   mPrefix->text() + data->name + mSuffix->text(),
00263                   mFontColourButton->bgColour(), mFontColourButton->fgColour(),
00264                   mFontColourButton->font(), KAEvent::MESSAGE, mLateCancel->minutes(),
00265                   mFlags, true);
00266         float fadeVolume;
00267         int   fadeSecs;
00268         float volume = mSoundPicker->volume(fadeVolume, fadeSecs);
00269         event.setAudioFile(mSoundPicker->file().prettyUrl(), volume, fadeVolume, fadeSecs);
00270         QList<int> months;
00271         months.append(date.month());
00272         event.setRecurAnnualByDate(1, months, 0, Preferences::defaultFeb29Type(), -1, QDate());
00273         event.setRepetition(mSubRepetition->interval(), mSubRepetition->count());
00274         event.setNextOccurrence(todayStart);
00275         if (reminder)
00276             event.setReminder(reminder, false);
00277         if (mSpecialActionsButton)
00278             event.setActions(mSpecialActionsButton->preAction(),
00279                      mSpecialActionsButton->postAction(),
00280                              mSpecialActionsButton->cancelOnError());
00281         event.endChanges();
00282         list.append(event);
00283     }
00284     return list;
00285 }
00286 
00287 /******************************************************************************
00288 * Called when the OK button is selected to import the selected birthdays.
00289 */
00290 void BirthdayDlg::slotOk()
00291 {
00292     // Save prefix and suffix texts to use as future defaults
00293     KConfigGroup config(KGlobal::config(), "General");
00294     config.writeEntry("BirthdayPrefix", mPrefix->text());
00295     config.writeEntry("BirthdaySuffix", mSuffix->text());
00296     config.sync();
00297 
00298     mFlags = (mSoundPicker->sound() == Preferences::Sound_Beep ? KAEvent::BEEP : 0)
00299            | (mSoundPicker->repeat()                     ? KAEvent::REPEAT_SOUND : 0)
00300            | (mConfirmAck->isChecked()                   ? KAEvent::CONFIRM_ACK : 0)
00301            | (mFontColourButton->defaultFont()           ? KAEvent::DEFAULT_FONT : 0)
00302            |                                               KAEvent::ANY_TIME;
00303     KDialog::accept();
00304 }
00305 
00306 /******************************************************************************
00307 * Called when the group of items selected changes.
00308 * Enable/disable the OK button depending on whether anything is selected.
00309 */
00310 void BirthdayDlg::slotSelectionChanged()
00311 {
00312     enableButtonOk(mListView->selectionModel()->hasSelection());
00313 }
00314 
00315 /******************************************************************************
00316 * Called when the font/color button has been clicked.
00317 * Set the colors in the message text entry control.
00318 */
00319 void BirthdayDlg::setColours(const QColor& fgColour, const QColor& bgColour)
00320 {
00321     QPalette pal = mPrefix->palette();
00322     pal.setColor(mPrefix->backgroundRole(), bgColour);
00323     pal.setColor(mPrefix->foregroundRole(), fgColour);
00324     mPrefix->setPalette(pal);
00325     mSuffix->setPalette(pal);
00326 }
00327 
00328 /******************************************************************************
00329 * Called when the data has changed in the birthday list.
00330 * Resize the date column.
00331 */
00332 void BirthdayDlg::resizeViewColumns()
00333 {
00334     mListView->resizeColumnToContents(BirthdayModel::DateColumn);
00335 }
00336 
00337 /******************************************************************************
00338 * Called when the prefix or suffix text has lost keyboard focus.
00339 * If the text has changed, re-evaluates the selection list according to the new
00340 * birthday alarm text format.
00341 */
00342 void BirthdayDlg::slotTextLostFocus()
00343 {
00344     QString prefix = mPrefix->text();
00345     QString suffix = mSuffix->text();
00346     if (prefix != mPrefixText  ||  suffix != mSuffixText)
00347     {
00348         // Text has changed - re-evaluate the selection list
00349         mPrefixText = prefix;
00350         mSuffixText = suffix;
00351         BirthdayModel::instance()->setPrefixSuffix(mPrefixText, mSuffixText);
00352     }
00353 }

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal