23 #include <tdeglobal.h>
24 #include <tdeconfig.h>
25 #include <kstandarddirs.h>
26 #include <tdeapplication.h>
27 #include <tdeglobalsettings.h>
28 #include <tdemessagebox.h>
30 #include <libkpimidentities/identity.h>
31 #include <libkpimidentities/identitymanager.h>
36 #include "messagebox.h"
37 #include "preferences.moc"
40 static TQString translateXTermPath(TDEConfig*,
const TQString& cmdline,
bool write);
42 Preferences* Preferences::mInstance = 0;
45 TQColor defaultMessageColours[] = { TQt::red, TQt::green, TQt::blue, TQt::cyan, TQt::magenta, TQt::yellow, TQt::white, TQt::lightGray, TQt::black, TQColor() };
46 const ColourList Preferences::default_messageColours(defaultMessageColours);
47 const TQColor Preferences::default_defaultBgColour(TQt::red);
48 const TQColor Preferences::default_defaultFgColour(TQt::black);
49 TQFont Preferences::mDefault_messageFont;
50 const TQTime Preferences::default_startOfDay(0, 0);
51 const bool Preferences::default_runInSystemTray =
true;
52 const bool Preferences::default_disableAlarmsIfStopped =
true;
53 const bool Preferences::default_quitWarn =
true;
54 const bool Preferences::default_autostartTrayIcon =
true;
55 const bool Preferences::default_confirmAlarmDeletion =
true;
56 const bool Preferences::default_modalMessages =
true;
57 const int Preferences::default_messageButtonDelay = 0;
58 const int Preferences::default_tooltipAlarmCount = 5;
59 const bool Preferences::default_showTooltipAlarmTime =
true;
60 const bool Preferences::default_showTooltipTimeToAlarm =
true;
61 const TQString Preferences::default_tooltipTimeToPrefix = TQString::fromLatin1(
"+");
62 const int Preferences::default_daemonTrayCheckInterval = 10;
63 const bool Preferences::default_emailCopyToKMail =
false;
64 const bool Preferences::default_emailQueuedNotify =
false;
65 const TQColor Preferences::default_disabledColour(TQt::lightGray);
66 const TQColor Preferences::default_expiredColour(TQt::darkRed);
67 const int Preferences::default_expiredKeepDays = 7;
68 const TQString Preferences::default_defaultSoundFile = TQString();
69 const float Preferences::default_defaultSoundVolume = -1;
70 const int Preferences::default_defaultLateCancel = 0;
71 const bool Preferences::default_defaultAutoClose =
false;
72 const bool Preferences::default_defaultCopyToKOrganizer =
false;
73 const bool Preferences::default_defaultSoundRepeat =
false;
74 const SoundPicker::Type Preferences::default_defaultSoundType = SoundPicker::NONE;
75 const bool Preferences::default_defaultConfirmAck =
false;
76 const bool Preferences::default_defaultCmdScript =
false;
77 const EditAlarmDlg::CmdLogType Preferences::default_defaultCmdLogType = EditAlarmDlg::DISCARD_OUTPUT;
78 const bool Preferences::default_defaultEmailBcc =
false;
79 const TQString Preferences::default_emailAddress = TQString();
80 const TQString Preferences::default_emailBccAddress = TQString();
81 const Preferences::MailClient Preferences::default_emailClient = KMAIL;
82 const Preferences::MailFrom Preferences::default_emailBccFrom = MAIL_FROM_CONTROL_CENTRE;
83 const RecurrenceEdit::RepeatType Preferences::default_defaultRecurPeriod = RecurrenceEdit::NO_RECUR;
84 const KARecurrence::Feb29Type Preferences::default_defaultFeb29Type = KARecurrence::FEB29_MAR1;
85 const TimePeriod::Units Preferences::default_defaultReminderUnits = TimePeriod::HOURS_MINUTES;
86 const TQString Preferences::default_defaultPreAction;
87 const TQString Preferences::default_defaultPostAction;
89 Preferences::MailFrom Preferences::default_emailFrom()
91 return KAMail::identitiesExist() ? MAIL_FROM_KMAIL : MAIL_FROM_CONTROL_CENTRE;
95 ColourList Preferences::mMessageColours;
96 TQColor Preferences::mDefaultBgColour;
97 TQFont Preferences::mMessageFont;
98 TQTime Preferences::mStartOfDay;
99 bool Preferences::mRunInSystemTray;
100 bool Preferences::mDisableAlarmsIfStopped;
101 bool Preferences::mAutostartTrayIcon;
102 KARecurrence::Feb29Type Preferences::mDefaultFeb29Type;
103 bool Preferences::mModalMessages;
104 int Preferences::mMessageButtonDelay;
105 int Preferences::mTooltipAlarmCount;
106 bool Preferences::mShowTooltipAlarmTime;
107 bool Preferences::mShowTooltipTimeToAlarm;
108 TQString Preferences::mTooltipTimeToPrefix;
109 int Preferences::mDaemonTrayCheckInterval;
110 TQString Preferences::mEmailAddress;
111 TQString Preferences::mEmailBccAddress;
112 Preferences::MailClient Preferences::mEmailClient;
113 Preferences::MailFrom Preferences::mEmailFrom;
114 Preferences::MailFrom Preferences::mEmailBccFrom;
115 bool Preferences::mEmailCopyToKMail;
116 TQString Preferences::mCmdXTermCommand;
117 TQColor Preferences::mDisabledColour;
118 TQColor Preferences::mExpiredColour;
119 int Preferences::mExpiredKeepDays;
121 TQString Preferences::mDefaultSoundFile;
122 float Preferences::mDefaultSoundVolume;
123 int Preferences::mDefaultLateCancel;
124 bool Preferences::mDefaultAutoClose;
125 bool Preferences::mDefaultCopyToKOrganizer;
126 SoundPicker::Type Preferences::mDefaultSoundType;
127 bool Preferences::mDefaultSoundRepeat;
128 bool Preferences::mDefaultConfirmAck;
129 bool Preferences::mDefaultEmailBcc;
130 bool Preferences::mDefaultCmdScript;
131 EditAlarmDlg::CmdLogType Preferences::mDefaultCmdLogType;
132 TQString Preferences::mDefaultCmdLogFile;
133 RecurrenceEdit::RepeatType Preferences::mDefaultRecurPeriod;
134 TimePeriod::Units Preferences::mDefaultReminderUnits;
135 TQString Preferences::mDefaultPreAction;
136 TQString Preferences::mDefaultPostAction;
138 TQTime Preferences::mOldStartOfDay;
139 bool Preferences::mStartOfDayChanged;
142 static const TQString defaultFeb29RecurType = TQString::fromLatin1(
"Mar1");
143 static const TQString defaultEmailClient = TQString::fromLatin1(
"kmail");
146 static const TQString GENERAL_SECTION = TQString::fromLatin1(
"General");
147 static const TQString VERSION_NUM = TQString::fromLatin1(
"Version");
148 static const TQString MESSAGE_COLOURS = TQString::fromLatin1(
"MessageColours");
149 static const TQString MESSAGE_BG_COLOUR = TQString::fromLatin1(
"MessageBackgroundColour");
150 static const TQString MESSAGE_FONT = TQString::fromLatin1(
"MessageFont");
151 static const TQString RUN_IN_SYSTEM_TRAY = TQString::fromLatin1(
"RunInSystemTray");
152 static const TQString DISABLE_IF_STOPPED = TQString::fromLatin1(
"DisableAlarmsIfStopped");
153 static const TQString AUTOSTART_TRAY = TQString::fromLatin1(
"AutostartTray");
154 static const TQString FEB29_RECUR_TYPE = TQString::fromLatin1(
"Feb29Recur");
155 static const TQString MODAL_MESSAGES = TQString::fromLatin1(
"ModalMessages");
156 static const TQString MESSAGE_BUTTON_DELAY = TQString::fromLatin1(
"MessageButtonDelay");
157 static const TQString TOOLTIP_ALARM_COUNT = TQString::fromLatin1(
"TooltipAlarmCount");
158 static const TQString TOOLTIP_ALARM_TIME = TQString::fromLatin1(
"ShowTooltipAlarmTime");
159 static const TQString TOOLTIP_TIME_TO_ALARM = TQString::fromLatin1(
"ShowTooltipTimeToAlarm");
160 static const TQString TOOLTIP_TIME_TO_PREFIX = TQString::fromLatin1(
"TooltipTimeToPrefix");
161 static const TQString DAEMON_TRAY_INTERVAL = TQString::fromLatin1(
"DaemonTrayCheckInterval");
162 static const TQString EMAIL_CLIENT = TQString::fromLatin1(
"EmailClient");
163 static const TQString EMAIL_COPY_TO_KMAIL = TQString::fromLatin1(
"EmailCopyToKMail");
164 static const TQString EMAIL_FROM = TQString::fromLatin1(
"EmailFrom");
165 static const TQString EMAIL_BCC_ADDRESS = TQString::fromLatin1(
"EmailBccAddress");
166 static const TQString CMD_XTERM_COMMAND = TQString::fromLatin1(
"CmdXTerm");
167 static const TQString START_OF_DAY = TQString::fromLatin1(
"StartOfDay");
168 static const TQString START_OF_DAY_CHECK = TQString::fromLatin1(
"Sod");
169 static const TQString DISABLED_COLOUR = TQString::fromLatin1(
"DisabledColour");
170 static const TQString EXPIRED_COLOUR = TQString::fromLatin1(
"ExpiredColour");
171 static const TQString EXPIRED_KEEP_DAYS = TQString::fromLatin1(
"ExpiredKeepDays");
172 static const TQString DEFAULTS_SECTION = TQString::fromLatin1(
"Defaults");
173 static const TQString DEF_LATE_CANCEL = TQString::fromLatin1(
"DefLateCancel");
174 static const TQString DEF_AUTO_CLOSE = TQString::fromLatin1(
"DefAutoClose");
175 static const TQString DEF_CONFIRM_ACK = TQString::fromLatin1(
"DefConfirmAck");
176 static const TQString DEF_COPY_TO_KORG = TQString::fromLatin1(
"DefCopyKOrg");
177 static const TQString DEF_SOUND_TYPE = TQString::fromLatin1(
"DefSoundType");
178 static const TQString DEF_SOUND_FILE = TQString::fromLatin1(
"DefSoundFile");
179 static const TQString DEF_SOUND_VOLUME = TQString::fromLatin1(
"DefSoundVolume");
180 static const TQString DEF_SOUND_REPEAT = TQString::fromLatin1(
"DefSoundRepeat");
181 static const TQString DEF_CMD_SCRIPT = TQString::fromLatin1(
"DefCmdScript");
182 static const TQString DEF_CMD_LOG_TYPE = TQString::fromLatin1(
"DefCmdLogType");
183 static const TQString DEF_LOG_FILE = TQString::fromLatin1(
"DefLogFile");
184 static const TQString DEF_EMAIL_BCC = TQString::fromLatin1(
"DefEmailBcc");
185 static const TQString DEF_RECUR_PERIOD = TQString::fromLatin1(
"DefRecurPeriod");
186 static const TQString DEF_REMIND_UNITS = TQString::fromLatin1(
"RemindUnits");
187 static const TQString DEF_PRE_ACTION = TQString::fromLatin1(
"DefPreAction");
188 static const TQString DEF_POST_ACTION = TQString::fromLatin1(
"DefPostAction");
191 static const TQString TEMP = TQString::fromLatin1(
"Temp");
194 static const TQString FROM_CONTROL_CENTRE = TQString::fromLatin1(
"@ControlCenter");
195 static const TQString FROM_KMAIL = TQString::fromLatin1(
"@KMail");
198 const TQString Preferences::QUIT_WARN = TQString::fromLatin1(
"QuitWarn");
199 const TQString Preferences::CONFIRM_ALARM_DELETION = TQString::fromLatin1(
"ConfirmAlarmDeletion");
200 const TQString Preferences::EMAIL_QUEUED_NOTIFY = TQString::fromLatin1(
"EmailQueuedNotify");
202 static const int SODxor = 0x82451630;
203 inline int Preferences::startOfDayCheck()
207 return TQTime().msecsTo(mStartOfDay) ^ SODxor;
211 void Preferences::initialise()
217 mDefault_messageFont = TQFont(TDEGlobalSettings::generalFont().family(), 16, TQFont::Bold);
219 mInstance =
new Preferences;
225 MessageBox::setContinueDefault(QUIT_WARN, KMessageBox::Cancel);
226 MessageBox::setDefaultShouldBeShownContinue(QUIT_WARN, default_quitWarn);
227 MessageBox::setDefaultShouldBeShownContinue(EMAIL_QUEUED_NOTIFY, default_emailQueuedNotify);
228 MessageBox::setDefaultShouldBeShownContinue(CONFIRM_ALARM_DELETION, default_confirmAlarmDeletion);
232 void Preferences::connect(
const char* signal,
const TQObject* receiver,
const char* member)
235 TQObject::connect(mInstance, signal, receiver, member);
238 void Preferences::emitStartOfDayChanged()
240 emit startOfDayChanged(mOldStartOfDay);
243 void Preferences::emitPreferencesChanged()
245 emit preferencesChanged();
251 void Preferences::read()
255 TDEConfig* config = TDEGlobal::config();
256 config->setGroup(GENERAL_SECTION);
257 TQStringList cols = config->readListEntry(MESSAGE_COLOURS);
259 mMessageColours = default_messageColours;
262 mMessageColours.clear();
263 for (TQStringList::Iterator it = cols.begin(); it != cols.end(); ++it)
267 mMessageColours.insert(c);
270 mDefaultBgColour = config->readColorEntry(MESSAGE_BG_COLOUR, &default_defaultBgColour);
271 mMessageFont = config->readFontEntry(MESSAGE_FONT, &mDefault_messageFont);
272 mRunInSystemTray = config->readBoolEntry(RUN_IN_SYSTEM_TRAY, default_runInSystemTray);
273 mDisableAlarmsIfStopped = config->readBoolEntry(DISABLE_IF_STOPPED, default_disableAlarmsIfStopped);
274 mAutostartTrayIcon = config->readBoolEntry(AUTOSTART_TRAY, default_autostartTrayIcon);
275 mModalMessages = config->readBoolEntry(MODAL_MESSAGES, default_modalMessages);
276 mMessageButtonDelay = config->readNumEntry(MESSAGE_BUTTON_DELAY, default_messageButtonDelay);
277 if (mMessageButtonDelay > 10)
278 mMessageButtonDelay = 10;
279 if (mMessageButtonDelay < -1)
280 mMessageButtonDelay = -1;
281 mTooltipAlarmCount =
static_cast<int>(config->readUnsignedNumEntry(TOOLTIP_ALARM_COUNT, default_tooltipAlarmCount));
282 if (mTooltipAlarmCount < 1)
283 mTooltipAlarmCount = 1;
284 mShowTooltipAlarmTime = config->readBoolEntry(TOOLTIP_ALARM_TIME, default_showTooltipAlarmTime);
285 mShowTooltipTimeToAlarm = config->readBoolEntry(TOOLTIP_TIME_TO_ALARM, default_showTooltipTimeToAlarm);
286 mTooltipTimeToPrefix = config->readEntry(TOOLTIP_TIME_TO_PREFIX, default_tooltipTimeToPrefix);
287 mDaemonTrayCheckInterval =
static_cast<int>(config->readUnsignedNumEntry(DAEMON_TRAY_INTERVAL, default_daemonTrayCheckInterval));
288 if (mDaemonTrayCheckInterval < 1)
289 mDaemonTrayCheckInterval = 1;
290 TQCString client = config->readEntry(EMAIL_CLIENT, defaultEmailClient).local8Bit();
291 mEmailClient = (client ==
"sendmail" ? SENDMAIL : KMAIL);
292 mEmailCopyToKMail = config->readBoolEntry(EMAIL_COPY_TO_KMAIL, default_emailCopyToKMail);
293 TQString from = config->readEntry(EMAIL_FROM, emailFrom(default_emailFrom(),
false,
false));
294 mEmailFrom = emailFrom(from);
295 TQString bccFrom = config->readEntry(EMAIL_BCC_ADDRESS, emailFrom(default_emailBccFrom,
false,
true));
296 mEmailBccFrom = emailFrom(bccFrom);
297 if (mEmailFrom == MAIL_FROM_CONTROL_CENTRE || mEmailBccFrom == MAIL_FROM_CONTROL_CENTRE)
298 mEmailAddress = mEmailBccAddress = KAMail::controlCentreAddress();
299 if (mEmailFrom == MAIL_FROM_ADDR)
300 mEmailAddress = from;
301 if (mEmailBccFrom == MAIL_FROM_ADDR)
302 mEmailBccAddress = bccFrom;
303 mCmdXTermCommand = translateXTermPath(config, config->readEntry(CMD_XTERM_COMMAND),
false);
304 TQDateTime defStartOfDay(TQDate(1900,1,1), default_startOfDay);
305 mStartOfDay = config->readDateTimeEntry(START_OF_DAY, &defStartOfDay).time();
306 mOldStartOfDay.setHMS(0,0,0);
307 int sod = config->readNumEntry(START_OF_DAY_CHECK, 0);
309 mOldStartOfDay = mOldStartOfDay.addMSecs(sod ^ SODxor);
310 mDisabledColour = config->readColorEntry(DISABLED_COLOUR, &default_disabledColour);
311 mExpiredColour = config->readColorEntry(EXPIRED_COLOUR, &default_expiredColour);
312 mExpiredKeepDays = config->readNumEntry(EXPIRED_KEEP_DAYS, default_expiredKeepDays);
314 config->setGroup(DEFAULTS_SECTION);
315 mDefaultLateCancel =
static_cast<int>(config->readUnsignedNumEntry(DEF_LATE_CANCEL, default_defaultLateCancel));
316 mDefaultAutoClose = config->readBoolEntry(DEF_AUTO_CLOSE, default_defaultAutoClose);
317 mDefaultConfirmAck = config->readBoolEntry(DEF_CONFIRM_ACK, default_defaultConfirmAck);
318 mDefaultCopyToKOrganizer = config->readBoolEntry(DEF_COPY_TO_KORG, default_defaultCopyToKOrganizer);
319 int soundType = config->readNumEntry(DEF_SOUND_TYPE, default_defaultSoundType);
320 mDefaultSoundType = (soundType < 0 || soundType > SoundPicker::SPEAK)
321 ? default_defaultSoundType : (SoundPicker::Type)soundType;
322 mDefaultSoundVolume =
static_cast<float>(config->readDoubleNumEntry(DEF_SOUND_VOLUME, default_defaultSoundVolume));
324 mDefaultSoundRepeat =
false;
326 mDefaultSoundRepeat = config->readBoolEntry(DEF_SOUND_REPEAT, default_defaultSoundRepeat);
328 mDefaultSoundFile = config->readPathEntry(DEF_SOUND_FILE);
329 mDefaultCmdScript = config->readBoolEntry(DEF_CMD_SCRIPT, default_defaultCmdScript);
330 int logType = config->readNumEntry(DEF_CMD_LOG_TYPE, default_defaultCmdLogType);
331 mDefaultCmdLogType = (logType < EditAlarmDlg::DISCARD_OUTPUT || logType > EditAlarmDlg::EXEC_IN_TERMINAL)
332 ? default_defaultCmdLogType : (EditAlarmDlg::CmdLogType)logType;
333 mDefaultCmdLogFile = config->readPathEntry(DEF_LOG_FILE);
334 mDefaultEmailBcc = config->readBoolEntry(DEF_EMAIL_BCC, default_defaultEmailBcc);
335 int recurPeriod = config->readNumEntry(DEF_RECUR_PERIOD, default_defaultRecurPeriod);
336 mDefaultRecurPeriod = (recurPeriod < RecurrenceEdit::SUBDAILY || recurPeriod > RecurrenceEdit::ANNUAL)
337 ? default_defaultRecurPeriod : (RecurrenceEdit::RepeatType)recurPeriod;
338 TQCString feb29 = config->readEntry(FEB29_RECUR_TYPE, defaultFeb29RecurType).local8Bit();
339 mDefaultFeb29Type = (feb29 ==
"Mar1") ? KARecurrence::FEB29_MAR1 : (feb29 ==
"Feb28") ? KARecurrence::FEB29_FEB28 : KARecurrence::FEB29_FEB29;
340 TQString remindUnits = config->readEntry(DEF_REMIND_UNITS);
341 mDefaultReminderUnits = (remindUnits == TQString::fromLatin1(
"Minutes")) ? TimePeriod::MINUTES
342 : (remindUnits == TQString::fromLatin1(
"HoursMinutes")) ? TimePeriod::HOURS_MINUTES
343 : (remindUnits == TQString::fromLatin1(
"Days")) ? TimePeriod::DAYS
344 : (remindUnits == TQString::fromLatin1(
"Weeks")) ? TimePeriod::WEEKS : default_defaultReminderUnits;
345 mDefaultPreAction = config->readEntry(DEF_PRE_ACTION, default_defaultPreAction);
346 mDefaultPostAction = config->readEntry(DEF_POST_ACTION, default_defaultPostAction);
347 mInstance->emitPreferencesChanged();
348 mStartOfDayChanged = (mStartOfDay != mOldStartOfDay);
349 if (mStartOfDayChanged)
351 mInstance->emitStartOfDayChanged();
352 mOldStartOfDay = mStartOfDay;
359 void Preferences::save(
bool syncToDisc)
361 TDEConfig* config = TDEGlobal::config();
362 config->setGroup(GENERAL_SECTION);
363 config->writeEntry(VERSION_NUM, KALARM_VERSION);
364 TQStringList colours;
365 for (ColourList::const_iterator it = mMessageColours.begin(); it != mMessageColours.end(); ++it)
366 colours.append(TQColor(*it).name());
367 config->writeEntry(MESSAGE_COLOURS, colours);
368 config->writeEntry(MESSAGE_BG_COLOUR, mDefaultBgColour);
369 config->writeEntry(MESSAGE_FONT, mMessageFont);
370 config->writeEntry(RUN_IN_SYSTEM_TRAY, mRunInSystemTray);
371 config->writeEntry(DISABLE_IF_STOPPED, mDisableAlarmsIfStopped);
372 config->writeEntry(AUTOSTART_TRAY, mAutostartTrayIcon);
373 config->writeEntry(MODAL_MESSAGES, mModalMessages);
374 config->writeEntry(MESSAGE_BUTTON_DELAY, mMessageButtonDelay);
375 config->writeEntry(TOOLTIP_ALARM_COUNT, mTooltipAlarmCount);
376 config->writeEntry(TOOLTIP_ALARM_TIME, mShowTooltipAlarmTime);
377 config->writeEntry(TOOLTIP_TIME_TO_ALARM, mShowTooltipTimeToAlarm);
378 config->writeEntry(TOOLTIP_TIME_TO_PREFIX, mTooltipTimeToPrefix);
379 config->writeEntry(DAEMON_TRAY_INTERVAL, mDaemonTrayCheckInterval);
380 config->writeEntry(EMAIL_CLIENT, (mEmailClient == SENDMAIL ?
"sendmail" :
"kmail"));
381 config->writeEntry(EMAIL_COPY_TO_KMAIL, mEmailCopyToKMail);
382 config->writeEntry(EMAIL_FROM, emailFrom(mEmailFrom,
true,
false));
383 config->writeEntry(EMAIL_BCC_ADDRESS, emailFrom(mEmailBccFrom,
true,
true));
384 config->writeEntry(CMD_XTERM_COMMAND, translateXTermPath(config, mCmdXTermCommand,
true));
385 config->writeEntry(START_OF_DAY, TQDateTime(TQDate(1900,1,1), mStartOfDay));
387 config->writeEntry(DISABLED_COLOUR, mDisabledColour);
388 config->writeEntry(EXPIRED_COLOUR, mExpiredColour);
389 config->writeEntry(EXPIRED_KEEP_DAYS, mExpiredKeepDays);
391 config->setGroup(DEFAULTS_SECTION);
392 config->writeEntry(DEF_LATE_CANCEL, mDefaultLateCancel);
393 config->writeEntry(DEF_AUTO_CLOSE, mDefaultAutoClose);
394 config->writeEntry(DEF_CONFIRM_ACK, mDefaultConfirmAck);
395 config->writeEntry(DEF_COPY_TO_KORG, mDefaultCopyToKOrganizer);
396 config->writeEntry(DEF_SOUND_TYPE, mDefaultSoundType);
397 config->writePathEntry(DEF_SOUND_FILE, mDefaultSoundFile);
398 config->writeEntry(DEF_SOUND_VOLUME,
static_cast<double>(mDefaultSoundVolume));
399 config->writeEntry(DEF_SOUND_REPEAT, mDefaultSoundRepeat);
400 config->writeEntry(DEF_CMD_SCRIPT, mDefaultCmdScript);
401 config->writeEntry(DEF_CMD_LOG_TYPE, mDefaultCmdLogType);
402 config->writePathEntry(DEF_LOG_FILE, mDefaultCmdLogFile);
403 config->writeEntry(DEF_EMAIL_BCC, mDefaultEmailBcc);
404 config->writeEntry(DEF_RECUR_PERIOD, mDefaultRecurPeriod);
405 config->writeEntry(FEB29_RECUR_TYPE, (mDefaultFeb29Type == KARecurrence::FEB29_MAR1 ?
"Mar1" : mDefaultFeb29Type == KARecurrence::FEB29_FEB28 ?
"Feb28" :
"None"));
407 switch (mDefaultReminderUnits)
409 case TimePeriod::MINUTES: value = TQString::fromLatin1(
"Minutes");
break;
410 case TimePeriod::HOURS_MINUTES: value = TQString::fromLatin1(
"HoursMinutes");
break;
411 case TimePeriod::DAYS: value = TQString::fromLatin1(
"Days");
break;
412 case TimePeriod::WEEKS: value = TQString::fromLatin1(
"Weeks");
break;
413 default: value = TQString();
break;
415 config->writeEntry(DEF_REMIND_UNITS, value);
416 config->writeEntry(DEF_PRE_ACTION, mDefaultPreAction);
417 config->writeEntry(DEF_POST_ACTION, mDefaultPostAction);
421 mInstance->emitPreferencesChanged();
422 if (mStartOfDay != mOldStartOfDay)
424 mInstance->emitStartOfDayChanged();
425 mOldStartOfDay = mStartOfDay;
429 void Preferences::syncToDisc()
431 TDEGlobal::config()->sync();
434 void Preferences::updateStartOfDayCheck()
436 TDEConfig* config = TDEGlobal::config();
437 config->setGroup(GENERAL_SECTION);
438 config->writeEntry(START_OF_DAY_CHECK, startOfDayCheck());
440 mStartOfDayChanged =
false;
443 TQString Preferences::emailFrom(Preferences::MailFrom from,
bool useAddress,
bool bcc)
447 case MAIL_FROM_KMAIL:
449 case MAIL_FROM_CONTROL_CENTRE:
450 return FROM_CONTROL_CENTRE;
452 return useAddress ? (bcc ? mEmailBccAddress : mEmailAddress) : TQString();
458 Preferences::MailFrom Preferences::emailFrom(
const TQString& str)
460 if (str == FROM_KMAIL)
461 return MAIL_FROM_KMAIL;
462 if (str == FROM_CONTROL_CENTRE)
463 return MAIL_FROM_CONTROL_CENTRE;
464 return MAIL_FROM_ADDR;
470 TQString Preferences::emailAddress()
474 case MAIL_FROM_KMAIL:
475 return KAMail::identityManager()->defaultIdentity().fullEmailAddr();
476 case MAIL_FROM_CONTROL_CENTRE:
477 return KAMail::controlCentreAddress();
479 return mEmailAddress;
485 TQString Preferences::emailBccAddress()
487 switch (mEmailBccFrom)
489 case MAIL_FROM_CONTROL_CENTRE:
490 return KAMail::controlCentreAddress();
492 return mEmailBccAddress;
498 void Preferences::setEmailAddress(Preferences::MailFrom from,
const TQString& address)
502 case MAIL_FROM_KMAIL:
504 case MAIL_FROM_CONTROL_CENTRE:
505 mEmailAddress = KAMail::controlCentreAddress();
508 mEmailAddress = address;
516 void Preferences::setEmailBccAddress(
bool useControlCentre,
const TQString& address)
518 if (useControlCentre)
519 mEmailBccAddress = KAMail::controlCentreAddress();
521 mEmailBccAddress = address;
522 mEmailBccFrom = useControlCentre ? MAIL_FROM_CONTROL_CENTRE : MAIL_FROM_ADDR;
529 void Preferences::setNotify(
const TQString& messageID,
bool notify)
531 MessageBox::saveDontShowAgainContinue(messageID, !notify);
541 bool Preferences::notifying(
const TQString& messageID)
543 return MessageBox::shouldBeShownContinue(messageID);
550 void Preferences::convertOldPrefs()
552 TDEConfig* config = TDEGlobal::config();
553 config->setGroup(GENERAL_SECTION);
554 int version = KAlarm::getVersionNumber(config->readEntry(VERSION_NUM));
555 if (version >= KAlarm::Version(1,4,22))
558 if (version <= KAlarm::Version(1,4,21))
561 static const TQString OLD_REMIND_UNITS = TQString::fromLatin1(
"DefRemindUnits");
562 config->setGroup(DEFAULTS_SECTION);
563 int intUnit = config->readNumEntry(OLD_REMIND_UNITS, 0);
564 TQString strUnit = (intUnit == 1) ? TQString::fromLatin1(
"Days")
565 : (intUnit == 2) ? TQString::fromLatin1(
"Weeks")
566 : TQString::fromLatin1(
"HoursMinutes");
567 config->deleteEntry(OLD_REMIND_UNITS);
568 config->writeEntry(DEF_REMIND_UNITS, strUnit);
571 if (version <= KAlarm::Version(1,4,20))
574 static const TQString VIEW_SECTION = TQString::fromLatin1(
"View");
575 static const TQString SHOW_ARCHIVED_ALARMS = TQString::fromLatin1(
"ShowArchivedAlarms");
576 static const TQString SHOW_EXPIRED_ALARMS = TQString::fromLatin1(
"ShowExpiredAlarms");
577 static const TQString SHOW_ALARM_TIME = TQString::fromLatin1(
"ShowAlarmTime");
578 static const TQString SHOW_TIME_TO_ALARM = TQString::fromLatin1(
"ShowTimeToAlarm");
579 config->setGroup(GENERAL_SECTION);
580 bool showExpired = config->readBoolEntry(SHOW_EXPIRED_ALARMS,
false);
581 bool showTime = config->readBoolEntry(SHOW_ALARM_TIME,
true);
582 bool showTimeTo = config->readBoolEntry(SHOW_TIME_TO_ALARM,
false);
583 config->deleteEntry(SHOW_EXPIRED_ALARMS);
584 config->deleteEntry(SHOW_ALARM_TIME);
585 config->deleteEntry(SHOW_TIME_TO_ALARM);
586 config->setGroup(VIEW_SECTION);
587 config->writeEntry(SHOW_ARCHIVED_ALARMS, showExpired);
588 config->writeEntry(SHOW_ALARM_TIME, showTime);
589 config->writeEntry(SHOW_TIME_TO_ALARM, showTimeTo);
592 if (version <= KAlarm::Version(1,4,5))
595 static const TQString DEF_SOUND = TQString::fromLatin1(
"DefSound");
596 config->setGroup(DEFAULTS_SECTION);
597 bool sound = config->readBoolEntry(DEF_SOUND,
false);
599 config->writeEntry(DEF_SOUND_TYPE, SoundPicker::NONE);
600 config->deleteEntry(DEF_SOUND);
603 if (version < KAlarm::Version(1,3,0))
606 static const TQString EMAIL_ADDRESS = TQString::fromLatin1(
"EmailAddress");
607 static const TQString EMAIL_USE_CTRL_CENTRE = TQString::fromLatin1(
"EmailUseControlCenter");
608 static const TQString EMAIL_BCC_USE_CTRL_CENTRE = TQString::fromLatin1(
"EmailBccUseControlCenter");
609 TQMap<TQString, TQString> entries = config->entryMap(GENERAL_SECTION);
610 if (entries.find(EMAIL_FROM) == entries.end()
611 && entries.find(EMAIL_USE_CTRL_CENTRE) != entries.end())
614 config->setGroup(GENERAL_SECTION);
616 bool bccUseCC =
false;
617 const bool default_emailUseControlCentre =
true;
618 const bool default_emailBccUseControlCentre =
true;
619 useCC = config->readBoolEntry(EMAIL_USE_CTRL_CENTRE, default_emailUseControlCentre);
621 bccUseCC = config->hasKey(EMAIL_BCC_USE_CTRL_CENTRE)
622 ? config->readBoolEntry(EMAIL_BCC_USE_CTRL_CENTRE, default_emailBccUseControlCentre)
624 config->writeEntry(EMAIL_FROM, (useCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_ADDRESS)));
625 config->writeEntry(EMAIL_BCC_ADDRESS, (bccUseCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_BCC_ADDRESS)));
626 config->deleteEntry(EMAIL_ADDRESS);
627 config->deleteEntry(EMAIL_BCC_USE_CTRL_CENTRE);
628 config->deleteEntry(EMAIL_USE_CTRL_CENTRE);
631 static const TQString DEF_CMD_XTERM = TQString::fromLatin1(
"DefCmdXterm");
632 config->setGroup(DEFAULTS_SECTION);
633 if (config->hasKey(DEF_CMD_XTERM))
635 config->writeEntry(DEF_CMD_LOG_TYPE,
636 (config->readBoolEntry(DEF_CMD_XTERM,
false) ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT));
637 config->deleteEntry(DEF_CMD_XTERM);
640 config->setGroup(GENERAL_SECTION);
641 config->writeEntry(VERSION_NUM, KALARM_VERSION);
654 TQString translateXTermPath(TDEConfig* config,
const TQString& cmdline,
bool write)
657 TQString cmd = cmdline;
658 if (cmdline.isEmpty())
661 TQChar quote = cmdline[0];
662 char q =
static_cast<char>(quote);
663 bool quoted = (q ==
'"' || q ==
'\'');
665 cmd = cmdline.mid(1);
667 for (
int i = 0, count = cmd.length(); i < count; ++i)
669 switch (cmd[i].latin1())
692 config->writePathEntry(TEMP, cmd);
693 cmd = config->readEntry(TEMP);
697 config->writeEntry(TEMP, cmd);
698 cmd = config->readPathEntry(TEMP);
700 config->deleteEntry(TEMP);
702 return quote + cmd + params;