diff options
Diffstat (limited to 'src/customtraylabel.cpp')
-rw-r--r-- | src/customtraylabel.cpp | 147 |
1 files changed, 47 insertions, 100 deletions
diff --git a/src/customtraylabel.cpp b/src/customtraylabel.cpp index e27dbba..87e50ac 100644 --- a/src/customtraylabel.cpp +++ b/src/customtraylabel.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004 Girish Ramakrishnan All Rights Reserved. - * + * * This 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 @@ -21,22 +21,25 @@ #include <tqsettings.h> #include <tqpopupmenu.h> -#include <tqmessagebox.h> +#include <tdepopupmenu.h> #include <tqfiledialog.h> #include <tqinputdialog.h> -#include <tqaction.h> #include <tqtimer.h> -#include <tqsize.h> #include <stdlib.h> +#include <khelpmenu.h> +#include <kstdaction.h> #include <kiconloader.h> +#include <kstdguiitem.h> +#include <tdeaction.h> +#include <tdeconfig.h> #include <tdeglobal.h> #include <tdelocale.h> +#include <tdemessagebox.h> #include "trace.h" -#include "customtraylabel.h" #include "traylabelmgr.h" -#include "tdedocker.h" +#include "customtraylabel.h" CustomTrayLabel::CustomTrayLabel(Window w, TQWidget* p, const TQString& t) : TQTrayLabel(w, p, t), mUndockWhenDead(false) @@ -51,34 +54,25 @@ CustomTrayLabel::CustomTrayLabel(const TQStringList& argv, pid_t pid, installMenu(); } -/* - * Installs a popup menu on the tray label - */ +// Installs a popup menu on the tray label void CustomTrayLabel::installMenu() { - //TQPixmap tdedocker_png(TDEGlobal::iconLoader()->loadIcon("tdedocker", TDEIcon::NoGroup, TDEIcon::SizeSmall)); - TQPixmap *tdedocker_png = new TQPixmap("tdedocker"); - setIcon(*tdedocker_png); + TQPixmap tdedocker_png(TDEGlobal::iconLoader()->loadIcon("tdedocker", TDEIcon::NoGroup, TDEIcon::SizeSmall)); + setIcon(tdedocker_png); TrayLabelMgr *tlMgr = TrayLabelMgr::instance(); - mOptionsMenu = new TQPopupMenu(this); + mOptionsMenu = new TDEPopupMenu(this); mSessionManagement = new TQAction(i18n("Dock when session restored"), 0, this); mSessionManagement->setToggleAction(true); connect(mSessionManagement, SIGNAL(toggled(bool)), this, SLOT(enableSessionManagement(bool))); mSessionManagement->addTo(mOptionsMenu); - mAutoLaunch = new TQAction(i18n("Launch on startup"), 0, this); - mAutoLaunch->setToggleAction(true); - connect(mAutoLaunch, SIGNAL(activated()), - this, SLOT(slotSetLaunchOnStartup())); - mAutoLaunch->addTo(mOptionsMenu); - mOptionsMenu->insertItem(i18n("Set Icon"), this, SLOT(setCustomIcon())); mBalloonTimeout = new TQAction(i18n("Set balloon timeout"), 0, this); connect(mBalloonTimeout, SIGNAL(activated()), - this, SLOT(slotSetBalloonTimeout())); + this, SLOT(slotSetBalloonTimeout())); mBalloonTimeout->addTo(mOptionsMenu); mDockWhenObscured = new TQAction(i18n("Dock when obscured"), 0, this); @@ -94,10 +88,10 @@ void CustomTrayLabel::installMenu() mDockWhenMinimized->addTo(mOptionsMenu); mDockWhenFocusLost = new TQAction(i18n("Dock when focus lost"), 0, this); - mDockWhenFocusLost->setToggleAction(true); - connect(mDockWhenFocusLost, SIGNAL(toggled(bool)), - this, SLOT(setDockWhenFocusLost(bool))); - mDockWhenFocusLost->addTo(mOptionsMenu); + mDockWhenFocusLost->setToggleAction(true); + connect(mDockWhenFocusLost, SIGNAL(toggled(bool)), + this, SLOT(setDockWhenFocusLost(bool))); + mDockWhenFocusLost->addTo(mOptionsMenu); mSkipTaskbar = new TQAction(i18n("Skip taskbar"), 0, this); mSkipTaskbar->setToggleAction(true); @@ -106,9 +100,6 @@ void CustomTrayLabel::installMenu() mSkipTaskbar->addTo(mOptionsMenu); mMainMenu = new TQPopupMenu(this); - mMainMenu->insertItem(TQIconSet(*tdedocker_png), - i18n("About TDEDocker"), tlMgr, SLOT(about())); - mMainMenu->insertSeparator(); mMainMenu->insertItem(i18n("Options"), mOptionsMenu); mMainMenu->insertItem(i18n("Dock Another"), tlMgr, SLOT(dockAnother())); mMainMenu->insertItem(i18n("Undock All"), tlMgr, SLOT(undockAll())); @@ -117,12 +108,15 @@ void CustomTrayLabel::installMenu() mShowId = mMainMenu->insertItem(TQString("Show/Hide [untitled]"), this, SLOT(toggleShow())); mMainMenu->insertItem(TQString(i18n("Undock")), this, SLOT(undock())); - mMainMenu->insertItem(TQString(i18n("Close")), this, SLOT(close())); + mMainMenu->insertSeparator(); + + mMainMenu->insertItem(SmallIcon("help"),KStdGuiItem::help().text(), (new KHelpMenu(this, TDEGlobal::instance()->aboutData()))->menu(), false); + TDEAction *quitAction = KStdAction::quit(this, SLOT(close()), NULL); + quitAction->plug(mMainMenu); connect(mMainMenu, SIGNAL(aboutToShow()), this, SLOT(updateMenu())); // Apply defaults here - setLaunchOnStartup(false); setDockWhenObscured(false); enableSessionManagement(true); mDockWhenMinimized->setOn(isDockWhenMinimized()); @@ -130,28 +124,21 @@ void CustomTrayLabel::installMenu() setAcceptDrops(true); // and you thought this function only installs the menu } -/* - * Session Management - */ -bool CustomTrayLabel::restoreState(TQSettings& settings) +// Session Management +bool CustomTrayLabel::restoreState(TDEConfig *config) { - mAutoLaunch->setOn(settings.readBoolEntry("/LaunchOnStartup")); - setDockWhenObscured(settings.readBoolEntry("/DockWhenObscured")); - TRACE("AutoLaunch=%i DWM=%i DWO=%i", isLaunchOnStartup(), - isDockWhenMinimized(), isDockWhenObscured()); - return TQTrayLabel::restoreState(settings); + setDockWhenObscured(config->readBoolEntry("DockWhenObscured", false)); + TRACE("DWM=%i DWO=%i", isDockWhenMinimized(), isDockWhenObscured()); + return TQTrayLabel::restoreState(config); } -bool CustomTrayLabel::saveState(TQSettings& settings) +void CustomTrayLabel::saveState(TDEConfig *config) { - if (!mSessionManagement->isOn()) return false; + if (!mSessionManagement->isOn()) return; - TQTrayLabel::saveState(settings); - settings.writeEntry("/LaunchOnStartup", isLaunchOnStartup()); - settings.writeEntry("/DockWhenObscured", isDockWhenObscured()); - TRACE("AutoLaunch=%i DWM=%i DWO=%i", isLaunchOnStartup(), - isDockWhenMinimized(), isDockWhenObscured()); - return true; + TQTrayLabel::saveState(config); + config->writeEntry("DockWhenObscured", isDockWhenObscured()); + TRACE("WM=%i DWO=%i", isDockWhenMinimized(), isDockWhenObscured()); } static bool which(const char *app) @@ -214,9 +201,8 @@ void CustomTrayLabel::setCustomIcon(void) icon = TQFileDialog::getOpenFileName(); if (icon.isNull()) return; // user cancelled if (!TQPixmap(icon).isNull()) break; - TRACE("Attempting to set icon to %s", icon.latin1()); - TQMessageBox::critical(this, i18n("TDEDocker"), - i18n("%1 is not a valid icon").arg(icon)); + TRACE("Attempting to set icon to %s", icon.local8Bit()); + KMessageBox::error(this, i18n("%1 is not a valid icon").arg(icon), i18n("TDEDocker")); } setTrayIcon(icon); @@ -228,56 +214,12 @@ void CustomTrayLabel::slotSetBalloonTimeout(void) bool ok; int timeout = TQInputDialog::getInteger(i18n("TDEDocker"), i18n("Enter balloon timeout (secs). 0 to disable ballooning"), - balloonTimeout()/1000, 0, 60, 1, &ok); - + balloonTimeout()/1000, 0, 60, 1, &ok); + if (!ok) return; setBalloonTimeout(timeout * 1000); } -void CustomTrayLabel::setLaunchOnStartup(bool launch) -{ - mAutoLaunch->setOn(launch); - slotSetLaunchOnStartup(); // fake an "activated" signal -} - -void CustomTrayLabel::slotSetLaunchOnStartup() -{ - TRACE("%i", mAutoLaunch->isOn()); - if (!mAutoLaunch->isOn()) return; - TQString app = appName(); - - TRACE("Validating %s", app.latin1()); - - while (true) - { - if (which(app.latin1())) - { - TRACE("Autolaunch enabled to %s", app.latin1()); - setAppName(app); - mAutoLaunch->setOn(true); - return; - } - - // Request user to provide file name himself - if (TQMessageBox::critical(NULL, i18n("TDEDocker"), - i18n("\"%1\" is not a valid executable " - "or was not found in your $PATH").arg(app), - i18n("Select program"), i18n("Cancel")) == 1) - { - mAutoLaunch->setOn(false); - return; // cancelled - } - - app = TQFileDialog::getOpenFileName(); - if (app.isNull()) - { - TRACE("Disabling auto launch"); - mAutoLaunch->setOn(false); - return; - } - } -} - // Called when we are just about to display the menu void CustomTrayLabel::updateMenu(void) { @@ -310,13 +252,19 @@ void CustomTrayLabel::obscureEvent(void) void CustomTrayLabel::focusLostEvent() { - if (mDockWhenFocusLost->isOn()) withdraw(); + if (mDockWhenFocusLost->isOn()) withdraw(); } -void CustomTrayLabel::mouseReleaseEvent(TQMouseEvent * ev) +void CustomTrayLabel::mouseReleaseEvent(TQMouseEvent *ev) { if (ev->button() == TQt::RightButton) + { mMainMenu->popup(ev->globalPos()); +/* contextMenuAboutToShow(contextMenu()); + contextMenu()->popup(e->globalPos()); + e->accept(); + return;*/ + } else toggleShow(); } @@ -356,9 +304,8 @@ bool CustomTrayLabel::canDockWindow(Window w) void CustomTrayLabel::dropEvent(TQDropEvent *) { - TQMessageBox::information(NULL, "TDEDocker", - i18n("You cannot drop an item into the tray icon. Drop it on the window\n" - "that is brought in front when you hover the item over the tray icon")); + KMessageBox::error(NULL, i18n("You cannot drop an item into the tray icon. Drop it on the window\n" + "that is brought in front when you hover the item over the tray icon"), i18n("TDEDocker")); } |