summaryrefslogtreecommitdiffstats
path: root/src/toplevel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/toplevel.cpp')
-rw-r--r--src/toplevel.cpp76
1 files changed, 62 insertions, 14 deletions
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();
}