diff options
author | Timothy Pearson <[email protected]> | 2012-06-11 03:18:26 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2012-06-11 03:18:26 -0500 |
commit | 49738635210f2cee1de883f71644149b1d50fa92 (patch) | |
tree | 117781c1c87fa0d7b0f6fc0fc0f87c94091321a4 /src | |
parent | 99c041312b58b99fe9beb139470598af71cebfae (diff) | |
download | kerberostray-49738635210f2cee1de883f71644149b1d50fa92.tar.gz kerberostray-49738635210f2cee1de883f71644149b1d50fa92.zip |
Add expiry warning and tooltips
Utility is now quite usable
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/configdlg.cpp | 65 | ||||
-rw-r--r-- | src/configdlg.h | 49 | ||||
-rw-r--r-- | src/configdlgbase.ui | 36 | ||||
-rw-r--r-- | src/cr22-action-kerberos_ticketexpiring.png | bin | 0 -> 1398 bytes | |||
-rw-r--r-- | src/toplevel.cpp | 76 | ||||
-rw-r--r-- | src/toplevel.h | 11 |
7 files changed, 223 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d508a2e..dac86b9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ INCLUDES= $(all_includes) $(KDE_INCLUDES)/tde bin_PROGRAMS = kerberostray -kerberostray_SOURCES = main.cpp toplevel.cpp +kerberostray_SOURCES = main.cpp toplevel.cpp configdlgbase.ui configdlg.cpp kerberostray_METASOURCES = AUTO kerberostray_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -lktexteditor -ltdeldap diff --git a/src/configdlg.cpp b/src/configdlg.cpp new file mode 100644 index 0000000..d6b6740 --- /dev/null +++ b/src/configdlg.cpp @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (C) 2012 by Timothy Pearson * + * [email protected] * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <klocale.h> +#include <klineedit.h> +#include <ktextedit.h> +#include <knuminput.h> +#include <kactionselector.h> +#include <tqlistbox.h> +#include <kpushbutton.h> +#include <tqpixmap.h> +#include <tqiconset.h> +#include <tqlabel.h> +#include <kconfig.h> +#include <tqcheckbox.h> + +#include "configdlgbase.h" +#include "configdlg.h" +#include "toplevel.h" + +KTMConfigureDialog::KTMConfigureDialog(TopLevel* tlapp, TQWidget* parent, const char* name) + : KDialogBase(parent, name, true, i18n("Kerberos Ticket Manager Configuration"), Ok|Cancel|Apply, Ok, true), m_tlapp(tlapp) +{ + m_base = new ConfigDlgBase(this); + + setMainWidget(m_base); + + m_base->notifyExpiry->setChecked(m_tlapp->notifyExpiry); + m_base->notifyExpiryMinutes->setValue(m_tlapp->notifyExpiryMinutes); +} + +void KTMConfigureDialog::save() { + m_tlapp->notifyExpiry = m_base->notifyExpiry->isOn(); + m_tlapp->notifyExpiryMinutes = m_base->notifyExpiryMinutes->value(); + + m_tlapp->save(); +} + +void KTMConfigureDialog::slotOk() { + save(); + accept(); +} + +void KTMConfigureDialog::slotApply() { + save(); +} + +#include "configdlg.moc" diff --git a/src/configdlg.h b/src/configdlg.h new file mode 100644 index 0000000..767910e --- /dev/null +++ b/src/configdlg.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2012 by Timothy Pearson * + * [email protected] * + * * + * 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 * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef _KTMCONFIGDIALOG_H_ +#define _KTMCONFIGDIALOG_H_ + +#include <kdialogbase.h> +#include <kcombobox.h> + +class ConfigDlgBase; +class TopLevel; + +class KTMConfigureDialog : public KDialogBase +{ + Q_OBJECT + +public: + KTMConfigureDialog(TopLevel* tlapp, TQWidget* parent = 0, const char* name = 0); + +public slots: + void slotOk(); + void slotApply(); + +public: + ConfigDlgBase *m_base; + TopLevel* m_tlapp; + +private: + void save(); +}; + +#endif diff --git a/src/configdlgbase.ui b/src/configdlgbase.ui new file mode 100644 index 0000000..8b55675 --- /dev/null +++ b/src/configdlgbase.ui @@ -0,0 +1,36 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>ConfigDlgBase</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>ConfigDlgBase</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQCheckBox" row="1" column="0" colspan="3"> + <property name="name"> + <cstring>notifyExpiry</cstring> + </property> + <property name="text"> + <string>Notify me before my ticket(s) expire</string> + </property> + </widget> + <widget class="TQLabel" row="2" column="0" colspan="2"> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="text"> + <string>Minutes before expiration:</string> + </property> + </widget> + <widget class="KIntNumInput" row="2" column="2"> + <property name="name"> + <cstring>notifyExpiryMinutes</cstring> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="3" margin="6"/> +<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +</UI> diff --git a/src/cr22-action-kerberos_ticketexpiring.png b/src/cr22-action-kerberos_ticketexpiring.png Binary files differnew file mode 100644 index 0000000..2354930 --- /dev/null +++ b/src/cr22-action-kerberos_ticketexpiring.png diff --git a/src/toplevel.cpp b/src/toplevel.cpp index bab925e..ed58951 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -53,10 +53,12 @@ #include <knotifydialog.h> #include <libtdeldap.h> +#include "configdlg.h" + #include "toplevel.h" #include "toplevel.moc" -TopLevel::TopLevel() : KSystemTray(), ticketWatch(0) +TopLevel::TopLevel() : KSystemTray(), ticketWatch(0), m_refreshTimer(0), notifyExpiryMinutes(0) { setBackgroundMode(X11ParentRelative); // what for? @@ -66,7 +68,7 @@ TopLevel::TopLevel() : KSystemTray(), ticketWatch(0) getNewTGTAct = new KAction(i18n("&Obtain New Ticket Granting Ticket"), "add_user", 0, TQT_TQOBJECT(this), TQT_SLOT(getNewTGT()), actionCollection(), "getnewtgt"); getNewSTAct = new KAction(i18n("&Obtain New Primary Service Ticket"), "add_user", 0, TQT_TQOBJECT(this), TQT_SLOT(getNewServiceTicket()), actionCollection(), "getnewserviceticket"); destroyAllAct = new KAction(i18n("&Destroy All Tickets"), "delete_user", 0, TQT_TQOBJECT(this), TQT_SLOT(destroyAllTickets()), actionCollection(), "destroyall"); -// confAct = new KAction(i18n("&Configure..."), "configure", 0, TQT_TQOBJECT(this), TQT_SLOT(config()), actionCollection(), "configure"); + confAct = new KAction(i18n("&Configure..."), "configure", 0, TQT_TQOBJECT(this), TQT_SLOT(config()), actionCollection(), "configure"); // create app menu (displayed on right-click) menu = new TQPopupMenu(); @@ -80,13 +82,15 @@ TopLevel::TopLevel() : KSystemTray(), ticketWatch(0) getNewSTAct->plug(menu); destroyAllAct->plug(menu); menu->insertSeparator(); -// confAct->plug(menu); + confAct->plug(menu); menu->insertItem(SmallIcon("help"), i18n("&Help"), helpMnu); menu->insertItem(SmallIcon("exit"), i18n("Quit"), kapp, TQT_SLOT(quit())); - // RAJA FIXME - // Should be on a timer or something + load(); + updateTicketList(); + + setupTimers(); } /* slot: signal shutDown() from KApplication */ @@ -103,16 +107,45 @@ void TopLevel::queryExit() TopLevel::~TopLevel() { if (ticketWatch) delete ticketWatch; + if (m_refreshTimer) m_refreshTimer->stop(); delete menu; // FIXME: must delete more (like all the TQWidgets in config-window)? } +void TopLevel::load() { + KConfig* config = KGlobal::instance()->config(); + config->setGroup(NULL); + notifyExpiry = config->readBoolEntry("notifyExpiry", true); + notifyExpiryMinutes = config->readNumEntry("notifyExpiryMinutes", 5); +} + +void TopLevel::save() { + KConfig* config = KGlobal::instance()->config(); + config->setGroup(NULL); + config->writeEntry("notifyExpiry", notifyExpiry); + config->writeEntry("notifyExpiryMinutes", notifyExpiryMinutes); + config->sync(); + + setupTimers(); +} + +void TopLevel::setupTimers() { + // FIXME + // Better would be to call updateTicketList() notifyExpiryMinutes before first ticket expiration + // For now this will work, but less efficiently + + if (!m_refreshTimer) { + m_refreshTimer = new TQTimer(this); + connect(m_refreshTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateTicketList())); + m_refreshTimer->start(10*1000, false); + } +} + void TopLevel::updateTicketList() { m_ticketList = LDAPManager::getKerberosTicketList(TQString::null, &m_ticketFile); m_ticketFile.replace("FILE:", ""); -printf("[RAJA DEBUG 980.0] Got ticket cache %s\n\r", m_ticketFile.ascii()); fflush(stdout); if (!ticketWatch) { ticketWatch = new KDirWatch(); @@ -128,10 +161,6 @@ printf("[RAJA DEBUG 980.0] Got ticket cache %s\n\r", m_ticketFile.ascii()); fflu ticketWatch->startScan(); } - // RAJA FIXME - // Find the next ticket expiry and set a timer to refresh just after expiry - // Better yet, how about flashing a warning when tickets are going to expire shortly? - repaint(); } @@ -167,7 +196,6 @@ void TopLevel::updateMenu() { } void TopLevel::getNewTicket(bool requestServiceTicket) { - // RAJA FIXME LDAPCredentials credentials; if (m_ticketList.count() > 0) { TQStringList princParts = TQStringList::split("@", m_ticketList[0].cachePrincipal); @@ -216,6 +244,7 @@ void TopLevel::resizeEvent ( TQResizeEvent * ) noTicketsPixmap = loadSizedIcon("kerberos_notickets", width()); expiredTicketsPixmap = loadSizedIcon("kerberos_expiredtickets", width()); partiallyExpiredTicketsPixmap = loadSizedIcon("kerberos_someexpiredtickets", width()); + expiringTicketsPixmap = loadSizedIcon("kerberos_ticketexpiring", width()); repaint(); } @@ -235,9 +264,12 @@ void TopLevel::mousePressEvent(TQMouseEvent *event) { /** Handle paintEvent (ie. animate icon) */ void TopLevel::paintEvent(TQPaintEvent *) { + TQString baseToolTip = i18n("%1 Kerberos ticket(s) listed for principal %2").arg(m_ticketList.count()).arg(m_ticketList[0].cachePrincipal); + TQPixmap *pm = &noTicketsPixmap; bool has_tickets = false; + bool tickets_expiring_soon = false; bool some_tickets_expired = false; bool all_tickets_expired = true; @@ -252,26 +284,41 @@ void TopLevel::paintEvent(TQPaintEvent *) { else { some_tickets_expired = true; } + if ((ticket.validEndTime > now) && (ticket.validEndTime < now.addSecs(notifyExpiryMinutes*60))) { + tickets_expiring_soon = true; + } } + if (!notifyExpiry) tickets_expiring_soon = false; + if (has_tickets) { if (all_tickets_expired) { pm = &expiredTicketsPixmap; + baseToolTip = baseToolTip + "\n" + i18n("All ticket(s) have expired"); + } + else if (tickets_expiring_soon) { + pm = &expiringTicketsPixmap; + baseToolTip = baseToolTip + "\n" + i18n("Ticket(s) will expire soon"); } else if (some_tickets_expired) { pm = &partiallyExpiredTicketsPixmap; + baseToolTip = baseToolTip + "\n" + i18n("Some ticket(s) have expired"); } else { pm = &activeTicketsPixmap; + baseToolTip = baseToolTip + "\n" + i18n("All ticket(s) are active"); } } - - // RAJA FIXME + else { + baseToolTip = i18n("No Kerberos tickets are available"); + } TQPixmap base(*pm); // make copy of base pixmap TQPainter p(this); p.drawPixmap(0, 0, base); p.end(); + + setToolTip(baseToolTip); } void TopLevel::timerEvent(TQTimerEvent *) { @@ -355,5 +402,6 @@ void TopLevel::help() { } void TopLevel::config() { - // + KTMConfigureDialog confdlg(this, this); + confdlg.exec(); } diff --git a/src/toplevel.h b/src/toplevel.h index c01c2ad..aedd1c7 100644 --- a/src/toplevel.h +++ b/src/toplevel.h @@ -44,7 +44,6 @@ class TimeEdit; class TopLevel : public KSystemTray { Q_OBJECT - public: @@ -58,10 +57,13 @@ protected: void resizeEvent(TQResizeEvent *); private slots: + void load(); + void save(); void config(); void help(); void setToolTip(const TQString &text, bool force=false); + void setupTimers(); void updateTicketList(); void updateMenu(); void getNewTGT(); @@ -76,6 +78,7 @@ private: TQPixmap noTicketsPixmap; TQPixmap expiredTicketsPixmap; TQPixmap partiallyExpiredTicketsPixmap; + TQPixmap expiringTicketsPixmap; KAction *confAct; KAction *getNewTGTAct; KAction *getNewSTAct; @@ -85,6 +88,12 @@ private: KerberosTicketInfoList m_ticketList; TQString m_ticketFile; KDirWatch *ticketWatch; + TQTimer *m_refreshTimer; + + bool notifyExpiry; + int notifyExpiryMinutes; + + friend class KTMConfigureDialog; }; #endif |