Add expiry warning and tooltips

Utility is now quite usable
pull/1/head
Timothy Pearson 13 years ago
parent 99c041312b
commit 4973863521

@ -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

@ -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 <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"

@ -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 <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

@ -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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -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();
}

@ -45,7 +45,6 @@ class TopLevel : public KSystemTray
{
Q_OBJECT
public:
TopLevel();
@ -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

Loading…
Cancel
Save