From 49738635210f2cee1de883f71644149b1d50fa92 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 11 Jun 2012 03:18:26 -0500 Subject: [PATCH] Add expiry warning and tooltips Utility is now quite usable --- src/Makefile.am | 2 +- src/configdlg.cpp | 65 +++++++++++++++++ src/configdlg.h | 49 +++++++++++++ src/configdlgbase.ui | 36 ++++++++++ src/cr22-action-kerberos_ticketexpiring.png | Bin 0 -> 1398 bytes src/toplevel.cpp | 76 ++++++++++++++++---- src/toplevel.h | 11 ++- 7 files changed, 223 insertions(+), 16 deletions(-) create mode 100644 src/configdlg.cpp create mode 100644 src/configdlg.h create mode 100644 src/configdlgbase.ui create mode 100644 src/cr22-action-kerberos_ticketexpiring.png 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 * + * kb9vqf@pearsoncomputing.net * + * * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 * + * kb9vqf@pearsoncomputing.net * + * * + * 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 +#include + +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 @@ + +ConfigDlgBase + + + ConfigDlgBase + + + + unnamed + + + + notifyExpiry + + + Notify me before my ticket(s) expire + + + + + unnamed + + + Minutes before expiration: + + + + + notifyExpiryMinutes + + + + + + + diff --git a/src/cr22-action-kerberos_ticketexpiring.png b/src/cr22-action-kerberos_ticketexpiring.png new file mode 100644 index 0000000000000000000000000000000000000000..2354930c028c0cb4655ca8513107e78cba380ce0 GIT binary patch literal 1398 zcmV-+1&R8JP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyh= z2Qw{2k}H(}00j0)L_t(I%e|CqOp{j_$N%r8Z|^Ow*p`k-DMFPoLC`2(7!#bh2yrfs z1aH}hb2GtAvtj(OW&5yX2{XoQ4i}BgKo%D9GM(8-)#y-}0*af8IHX_;r9kg3#rExc z_5o$W663OD=gWD{KRLhiJWrng0sf~&C2y$TzNh|9@3GdQVB^)H;Er#u-bu(T+3=sJ z#+B6{H{FboKCeJ}Mq;FABt~pLLJqfhi7IQ&d;f;TOh%l^Qu;wn-OH(3v27#*XMo3` zpNGQ}ghM`C@ z8znDhEq&gM{|0j+sYuKq5Cs5V_Wu+3h+NMHW! z{MDAiiUYU#^Y$3&2@2$1Kp<8-AshC$j~%QkKDTLU(x=m}tj$e)>-#-r=bx?~(+=V} zZ+x_Sd5(z*x+7?J0Td|6#T1t0TBI0Cn%nETRy!T+lbCwj$IVgzVgUR2Y6MB#*(5e{x#^o7H3;OrGT>?Yl>a_)KUswq0^HcSDeR@|{*NF7sx0*;K z5}tJ0<6Tw!*@f$cujX4MR1_>bArk;Z0C--&us4XZk*}f|SvedInlduY1`%f7twY8v3MmUB zNRga{?8YHz6fD$o25EUqaM5}OQO`q=SOm04f|S%WghC-`wOTkF4tF>l9-i`73_rAm z^-AfA9RDfltjr#?9d*L892o0bn zaAvbvp-?CiL?RK>*4EZMWo#PP%g#Bh^T<#$$nkX`Lroy|dXOWVQ(doB>^x+ix9t7J zY09m`ZB4}8d4}xWl2;1=YPCAAp`l@*qoaegwzdjIMMYaCTXB3H-Z3w<6dC3W0m9># z1R%)-yks2EZ5!X$+WY(E+H`}WFF0Zs1U`ye51fAhfZy-$sH&=3-`(A9SE*D~b#?WZ zCX*?fKJg|@GF|fSoQ(`+ zq*|}nd(CRKUg_)Wi>IfjCzh0yRMH|@LRIEk{cINP01qf<0J>B_sR0lNSO%Dz6`C!V zVwZ>$CvfrvM1o#Vzx&aHr#cz0tE=1E+1Yu+=kuYzzu&`3H1sZAhI7JjLZaWYj z1tc>kG=l-OR)y^;bFw2K0<1rsYzd4D&S~xr?b}rB6WJB?Yfsrh|qKITZW0?^c7an=CvKkGmH3jod+X4my!WB>pF07*qoM6N<$ Ef+o*+HUIzs literal 0 HcmV?d00001 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 #include +#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