summaryrefslogtreecommitdiffstats
path: root/kteatime/toplevel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kteatime/toplevel.cpp')
-rw-r--r--kteatime/toplevel.cpp177
1 files changed, 107 insertions, 70 deletions
diff --git a/kteatime/toplevel.cpp b/kteatime/toplevel.cpp
index 2d0ee03..325fe13 100644
--- a/kteatime/toplevel.cpp
+++ b/kteatime/toplevel.cpp
@@ -28,16 +28,16 @@
#include <tqhbox.h>
#include <tqvbox.h>
#include <tqlineedit.h>
+#include <tqlistview.h>
#include <tqpainter.h>
#include <tqtooltip.h>
#include <tqfile.h>
#include <tqcursor.h>
#include <tqpushbutton.h>
#include <tqgroupbox.h>
-#include <tqheader.h>
-#include <tqpixmap.h>
#include <tqbitmap.h>
+#include <tdeapplication.h>
#include <tdeconfig.h>
#include <khelpmenu.h>
#include <kiconloader.h>
@@ -45,17 +45,14 @@
#include <tdemessagebox.h>
#include <kpassivepopup.h>
#include <knotifyclient.h>
-#include <knuminput.h>
-#include <kseparator.h>
+#include <knotifydialog.h>
#include <tdepopupmenu.h>
#include <kdialogbase.h>
#include <tdeaction.h>
-#include <knotifydialog.h>
#include "tealist.h"
#include "timeedit.h"
#include "toplevel.h"
-#include "toplevel.moc"
const int TopLevel::DEFAULT_TEA_TIME = 3*60;
@@ -69,7 +66,7 @@ TopLevel::TopLevel() : KSystemTray()
teas.clear();
- TDEConfig *config = kapp->config();
+ TDEConfig *config = tdeApp->config();
config->setGroup("Teas");
if (config->hasKey("Number")) {
@@ -115,27 +112,27 @@ TopLevel::TopLevel() : KSystemTray()
current_selected = 0;
listempty = (teas.count() == 0);
-
+ popupBox = nullptr;
startAct = new TDEAction(i18n("&Start"), "1rightarrow", 0,
- TQT_TQOBJECT(this), TQT_SLOT(start()), actionCollection(), "start");
+ this, TQ_SLOT(start()), actionCollection(), "start");
stopAct = new TDEAction(i18n("Sto&p"), "cancel", 0,
- TQT_TQOBJECT(this), TQT_SLOT(stop()), actionCollection(), "stop");
+ this, TQ_SLOT(stop()), actionCollection(), "stop");
confAct = new TDEAction(i18n("&Configure..."), "configure", 0,
- TQT_TQOBJECT(this), TQT_SLOT(config()), actionCollection(), "configure");
+ this, TQ_SLOT(config()), actionCollection(), "configure");
anonAct = new TDEAction(i18n("&Anonymous..."), 0, 0,
- TQT_TQOBJECT(this), TQT_SLOT(anonymous()), actionCollection(), "anonymous");
+ this, TQ_SLOT(anonymous()), actionCollection(), "anonymous");
// TDEAction *quitAct = actionCollection()->action("file_quit");
// create app menu (displayed on right-click)
menu = new TQPopupMenu();
menu->setCheckable(true);
- connect(menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(teaSelected(int)));
+ connect(menu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(teaSelected(int)));
// this menu will be displayed when no tea is steeping, and left mouse button is clicked
start_menu = new TQPopupMenu();
start_menu->setCheckable(true); // menu isn't tickable, but this gives some add. spacing
- connect(start_menu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(teaStartSelected(int)));
+ connect(start_menu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(teaStartSelected(int)));
rebuildTeaMenus(); // populate tops of menus with tea-entries from config
@@ -152,13 +149,13 @@ TopLevel::TopLevel() : KSystemTray()
menu->insertSeparator();
confAct->plug(menu);
menu->insertItem(SmallIcon("help"), i18n("&Help"), helpMnu);
- menu->insertItem(SmallIcon("system-log-out"), i18n("Quit"), kapp, TQT_SLOT(quit()));
+ menu->insertItem(SmallIcon("system-log-out"), i18n("Quit"), tdeApp, TQ_SLOT(quit()));
// quitAct->plug(menu); // FIXME: this doesn't seem to work with above definition of quitAct?
// (need special 'quit'-method?)
// this menu will be displayed when a tea is steeping, and left mouse button is clicked
steeping_menu = new TQPopupMenu();
-// steeping_menu->insertItem(SmallIcon("cancel"), i18n("Just &Cancel Current"), this, TQT_SLOT(stop()));
+// steeping_menu->insertItem(SmallIcon("cancel"), i18n("Just &Cancel Current"), this, TQ_SLOT(stop()));
stopAct->plug(steeping_menu); // FIXME: can provide different text for this incarnation?
// start_menu->insertSeparator();
@@ -167,6 +164,7 @@ TopLevel::TopLevel() : KSystemTray()
// read remaining entries from config-file
useNotify = config->readBoolEntry("Beep", true); // "Beep" should really be named "Notify"
usePopup = config->readBoolEntry("Popup", true);
+ useResetOnPopup = config->readBoolEntry("ResetOnPopupClick", false);
useAction = config->readBoolEntry("UseAction", true);
action = config->readEntry("Action");
useTrayVis = config->readBoolEntry("UseTrayVis", true);
@@ -182,16 +180,6 @@ TopLevel::TopLevel() : KSystemTray()
stop(); // reset timer, disable some menu entries, etc.
}
-/* slot: signal shutDown() from TDEApplication */
-/* (not currently needed)
-void TopLevel::queryExit()
-{
- TDEConfig *config = kapp->config();
-// config->sync();
-}
-*/
-
-
/** Destructor */
TopLevel::~TopLevel()
{
@@ -225,7 +213,7 @@ void TopLevel::showEvent ( TQShowEvent * )
/** Handle mousePressEvent */
void TopLevel::mousePressEvent(TQMouseEvent *event)
{
- if (event->button() == Qt::LeftButton) {
+ if (event->button() == TQt::LeftButton) {
if (ready) {
stop(); // reset tooltip and stop animation
} else {
@@ -234,7 +222,7 @@ void TopLevel::mousePressEvent(TQMouseEvent *event)
else
start_menu->popup(TQCursor::pos());
}
- } else if (event->button() == Qt::RightButton)
+ } else if (event->button() == TQt::RightButton)
menu->popup(TQCursor::pos());
// else if (event->button() == MidButton) // currently unused
}
@@ -325,9 +313,11 @@ void TopLevel::timerEvent(TQTimerEvent *)
system(TQFile::encodeName(cmd));
}
if (usePopup)
- KPassivePopup::message(i18n("The Tea Cooker"),
- teaMessage, teaAnim1Pixmap, this, "popup", 0);
- // FIXME: does auto-deletion work without timeout?
+ {
+ popupBox = KPassivePopup::message(i18n("The Tea Cooker"),
+ teaMessage, teaAnim1Pixmap, this, "popup", 0);
+ connect(popupBox, TQ_SIGNAL(clicked()), this, TQ_SLOT(popupClicked()));
+ }
setToolTip(teaMessage);
repaint();
} else {
@@ -421,7 +411,7 @@ void TopLevel::teaSelected(int index)
menu->setItemChecked(index, true);
current_selected = index;
- TDEConfig *config = kapp->config();
+ TDEConfig *config = tdeApp->config();
config->setGroup("General");
config->writeEntry("Tea", current_selected);
}
@@ -452,11 +442,12 @@ void TopLevel::start()
}
// else both are already defined by dialog handler
- TQT_TQOBJECT(this)->killTimers();
+ this->killTimers();
startTimer(1000); // 1000ms = 1s (sufficient resolution)
running = true;
ready = false;
+ firstFrame = true;
enable_menuEntries(); // disable "start", enable "stop"
repaint();
@@ -466,7 +457,7 @@ void TopLevel::start()
/* menu-slot: "stop" selected in menu */
void TopLevel::stop()
{
- TQT_TQOBJECT(this)->killTimers();
+ this->killTimers();
running = false;
ready = false;
@@ -480,6 +471,23 @@ void TopLevel::stop()
setToolTip(i18n("The Tea Cooker"), true);
repaint();
+
+ // Close popup if still open. The popupBox autodeletes when
+ // hidden, so no need to manually delete it
+ if (popupBox)
+ {
+ popupBox->hide();
+ popupBox = nullptr;
+ }
+}
+
+void TopLevel::popupClicked()
+{
+ popupBox = nullptr;
+ if (usePopup && useResetOnPopup)
+ {
+ stop(); // reset tooltip and stop animation
+ }
}
/* open dialog to start an 'anonymous' tea */
@@ -648,6 +656,16 @@ void TopLevel::downButtonClicked() {
enable_controls();
}
+void TopLevel::eventEnableToggled(bool on)
+{
+ btn_conf->setEnabled(on);
+}
+
+void TopLevel::popupEnableToggled(bool on)
+{
+ resetOnPopupEnable->setEnabled(on);
+}
+
/* config-slot: checkbox next to "action" field toggled*/
void TopLevel::actionEnableToggled(bool on)
{
@@ -657,7 +675,7 @@ void TopLevel::actionEnableToggled(bool on)
/* config-slot: "help" button clicked */
void TopLevel::help()
{
- kapp->invokeHelp();
+ tdeApp->invokeHelp();
}
/* config-slot: "Configure Events..." button clicked */
@@ -682,7 +700,7 @@ void TopLevel::config()
/* left side - tea list and list-modifying buttons */
TQBoxLayout *leftside = new TQVBoxLayout(box);
- TQGroupBox *listgroup = new TQGroupBox(2,Qt::Vertical, i18n("Tea List"), page);
+ TQGroupBox *listgroup = new TQGroupBox(2,TQt::Vertical, i18n("Tea List"), page);
leftside->addWidget(listgroup, 0, 0);
listbox = new TQListView(listgroup, "listBox");
@@ -691,7 +709,7 @@ void TopLevel::config()
listbox->addColumn(i18n("Time"));
listbox->header()->setClickEnabled(false, listbox->header()->count()-1);
listbox->setSorting(-1);
- connect(listbox, TQT_SIGNAL(selectionChanged()), TQT_SLOT(listBoxItemSelected()));
+ connect(listbox, TQ_SIGNAL(selectionChanged()), TQ_SLOT(listBoxItemSelected()));
// now buttons for editing the tea-list
TQWidget *listgroup_widget = new TQWidget(listgroup);
@@ -701,36 +719,38 @@ void TopLevel::config()
TQToolTip::add(btn_new, i18n("New"));
btn_new->setPixmap(SmallIcon("document-new"));
btn_new->setMinimumSize(btn_new->sizeHint() * 1.2);
- connect(btn_new, TQT_SIGNAL(clicked()), TQT_SLOT(newButtonClicked()));
+ connect(btn_new, TQ_SIGNAL(clicked()), TQ_SLOT(newButtonClicked()));
hbox->addWidget(btn_new);
btn_del = new TQPushButton(TQString(), listgroup_widget);
TQToolTip::add(btn_del, i18n("Delete"));
btn_del->setIconSet(SmallIconSet("edit-delete"));
btn_del->setMinimumSize(btn_new->sizeHint() * 1.2);
- connect(btn_del, TQT_SIGNAL(clicked()), TQT_SLOT(delButtonClicked()));
+ connect(btn_del, TQ_SIGNAL(clicked()), TQ_SLOT(delButtonClicked()));
hbox->addWidget(btn_del);
btn_up = new TQPushButton(TQString(), listgroup_widget);
TQToolTip::add(btn_up, i18n("Up"));
btn_up->setIconSet(SmallIconSet("go-up"));
btn_up->setMinimumSize(btn_up->sizeHint() * 1.2);
- connect(btn_up, TQT_SIGNAL(clicked()), TQT_SLOT(upButtonClicked()));
+ connect(btn_up, TQ_SIGNAL(clicked()), TQ_SLOT(upButtonClicked()));
hbox->addWidget(btn_up);
btn_down = new TQPushButton(TQString(), listgroup_widget);
TQToolTip::add(btn_down, i18n("Down"));
btn_down->setIconSet(SmallIconSet("go-down"));
btn_down->setMinimumSize(btn_down->sizeHint() * 1.2);
- connect(btn_down, TQT_SIGNAL(clicked()), TQT_SLOT(downButtonClicked()));
+ connect(btn_down, TQ_SIGNAL(clicked()), TQ_SLOT(downButtonClicked()));
hbox->addWidget(btn_down);
hbox->addStretch(10);
/* right side - tea properties */
TQBoxLayout *rightside = new TQVBoxLayout(box);
- editgroup = new TQGroupBox(2,Qt::Vertical, i18n("Tea Properties"), page);
+ editgroup = new TQGroupBox(2,TQt::Vertical, i18n("Tea Properties"), page);
rightside->addWidget(editgroup, 0, 0);
+ rightside->addStretch();
+
TQHBox *propbox = new TQHBox(editgroup);
// FIXME: - must enforce correct vertical alignment of each label-editor pair
@@ -742,49 +762,59 @@ void TopLevel::config()
nameEdit->setAlignment(TQLineEdit::AlignLeft);
TQLabel *l = new TQLabel(nameEdit, i18n("Name:"), propleft);
l->setFixedSize(l->sizeHint());
- connect(nameEdit, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(nameEditTextChanged(const TQString&)) );
+ connect(nameEdit, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(nameEditTextChanged(const TQString&)) );
timeEdit = new TimeEdit(propright);
timeEdit->setFixedHeight(timeEdit->sizeHint().height());
l = new TQLabel(timeEdit, i18n("Tea time:"), propleft);
l->setFixedSize(l->sizeHint());
- connect(timeEdit, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(spinBoxValueChanged(int)));
+ connect(timeEdit, TQ_SIGNAL(valueChanged(int)), TQ_SLOT(spinBoxValueChanged(int)));
/* bottom - timeout actions */
- TQGroupBox *actiongroup = new TQGroupBox(4,Qt::Vertical, i18n("Action"), page);
- top_box->addWidget(actiongroup, 0, 0);
-
- TQWidget *actionconf_widget = new TQWidget(actiongroup);
- TQBoxLayout *actionconf_hbox = new TQHBoxLayout(actionconf_widget);
- btn_conf = new TQPushButton(i18n("Configure Events..."), actionconf_widget);
- actionconf_hbox->addWidget(btn_conf);
- connect(btn_conf, TQT_SIGNAL(clicked()), TQT_SLOT(confButtonClicked()));
- actionconf_hbox->addStretch(10);
-
- eventEnable = new TQCheckBox(i18n("Event"), actiongroup);
- popupEnable = new TQCheckBox(i18n("Popup"), actiongroup);
- eventEnable->setFixedHeight(eventEnable->sizeHint().height());
- popupEnable->setFixedHeight(popupEnable->sizeHint().height());
-
- TQHBox *actionbox = new TQHBox(actiongroup);
- actionEnable = new TQCheckBox(actionbox);
-// FIXME: add text to this line:
-// TQLabel *actionLabel = new TQLabel(i18n("Execute: "), actiongroup);
- actionEdit = new TQLineEdit(actionbox);
+ TQGridLayout *actionsGrid = new TQGridLayout(top_box, 5, 2, 5);
+ TQLabel *actionsLabel = new TQLabel(i18n("Actions"), page);
+ TQFont actionsLblFont = actionsLabel->font();
+ actionsLblFont.setBold(true);
+ actionsLabel->setFont(actionsLblFont);
+ actionsGrid->addMultiCellWidget(actionsLabel, 0, 0, 0, 1);
+
+ eventEnable = new TQCheckBox(i18n("Event"), page);
+ TQToolTip::add(eventEnable, i18n("Enable events when the tea is ready"));
+ connect(eventEnable, TQ_SIGNAL(toggled(bool)), TQ_SLOT(eventEnableToggled(bool)));
+ actionsGrid->addWidget(eventEnable, 1, 0);
+
+ btn_conf = new TQPushButton(i18n("Configure Events..."), page);
+ btn_conf->setFixedSize(btn_conf->sizeHint());
+ connect(btn_conf, TQ_SIGNAL(clicked()), TQ_SLOT(confButtonClicked()));
+ actionsGrid->addWidget(btn_conf, 1, 1);
+
+ popupEnable = new TQCheckBox(i18n("Popup"), page);
+ TQToolTip::add(popupEnable, i18n("Show a popup notification when the tea is ready"));
+ connect(popupEnable, TQ_SIGNAL(toggled(bool)), TQ_SLOT(popupEnableToggled(bool)));
+ actionsGrid->addWidget(popupEnable, 2, 0);
+
+ resetOnPopupEnable = new TQCheckBox(i18n("Reset on popup click"), page);
+ TQToolTip::add(resetOnPopupEnable, i18n("Reset tea when the popup notification is clicked"));
+ actionsGrid->addWidget(resetOnPopupEnable, 2, 1);
+
+ actionEnable = new TQCheckBox(i18n("Command"), page);
+ TQToolTip::add(actionEnable, i18n("Run a command when the tea is ready"));
+ connect(actionEnable, TQ_SIGNAL(toggled(bool)), TQ_SLOT(actionEnableToggled(bool)));
+ actionsGrid->addWidget(actionEnable, 3, 0);
+
+ actionEdit = new TQLineEdit(page);
actionEdit->setFixedHeight(actionEdit->sizeHint().height());
TQToolTip::add(actionEdit, i18n("Enter command here; '%t' will be replaced with name of steeping tea"));
- connect(actionEnable, TQT_SIGNAL(toggled(bool)), TQT_SLOT(actionEnableToggled(bool)));
- rightside->addStretch();
+ actionsGrid->addWidget(actionEdit, 3, 1);
// single checkbox
visEnable = new TQCheckBox(i18n("Visualize progress in icon tray"), page);
- top_box->addWidget(visEnable, 0, 0);
-
+ actionsGrid->addMultiCellWidget(visEnable, 4, 4, 0, 1);
// let listbox claim all remaining vertical space
top_box->setStretchFactor(box, 10);
- connect(confdlg, TQT_SIGNAL(helpClicked()), TQT_SLOT(help()));
+ connect(confdlg, TQ_SIGNAL(helpClicked()), TQ_SLOT(help()));
}
// now add all defined teas (and their times) to the listview
@@ -811,7 +841,10 @@ void TopLevel::config()
// -------------------------
eventEnable->setChecked(useNotify);
+ btn_conf->setEnabled(useNotify);
popupEnable->setChecked(usePopup);
+ resetOnPopupEnable->setChecked(useResetOnPopup);
+ resetOnPopupEnable->setEnabled(usePopup);
actionEnable->setChecked(useAction);
actionEdit->setText(action);
actionEdit->setEnabled(useAction);
@@ -822,6 +855,7 @@ void TopLevel::config()
// activate new settings
useNotify = eventEnable->isChecked();
usePopup = popupEnable->isChecked();
+ useResetOnPopup = resetOnPopupEnable->isChecked();
useAction = actionEnable->isChecked();
action = actionEdit->text();
useTrayVis = visEnable->isChecked();
@@ -845,7 +879,7 @@ void TopLevel::config()
rebuildTeaMenus();
// and store to config
- TDEConfig *config = kapp->config();
+ TDEConfig *config = tdeApp->config();
// remove old-style entries from default-group (if present)
if (config->hasKey("UserTea"))
config->deleteEntry("UserTea");
@@ -853,6 +887,7 @@ void TopLevel::config()
config->setGroup("General");
config->writeEntry("Beep", useNotify);
config->writeEntry("Popup", usePopup);
+ config->writeEntry("ResetOnPopupClick", useResetOnPopup);
config->writeEntry("UseAction", useAction);
config->writeEntry("Action", action);
config->writeEntry("Tea", current_selected);
@@ -874,3 +909,5 @@ void TopLevel::config()
config->sync();
}
}
+
+#include "toplevel.moc"