summaryrefslogtreecommitdiffstats
path: root/tdmlib/tdmtsak.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2015-09-29 19:43:26 -0500
committerTimothy Pearson <[email protected]>2015-09-29 19:43:26 -0500
commit6d028f3b522b5a4f978d52cc5b3c187cf329c3b2 (patch)
tree9e8c239eda85a8d7d2c9067f826a1e199ebf195f /tdmlib/tdmtsak.cpp
parentcd13be0789411619698e3d5d8483b85ca1bad7c0 (diff)
downloadtdebase-6d028f3b522b5a4f978d52cc5b3c187cf329c3b2.tar.gz
tdebase-6d028f3b522b5a4f978d52cc5b3c187cf329c3b2.zip
Use DM library in tdmtsak instead of making command line calls
Diffstat (limited to 'tdmlib/tdmtsak.cpp')
-rw-r--r--tdmlib/tdmtsak.cpp94
1 files changed, 54 insertions, 40 deletions
diff --git a/tdmlib/tdmtsak.cpp b/tdmlib/tdmtsak.cpp
index c893f86ec..768bcda80 100644
--- a/tdmlib/tdmtsak.cpp
+++ b/tdmlib/tdmtsak.cpp
@@ -1,6 +1,6 @@
/*
This file is part of the TDE project
- Copyright (C) 2011 Timothy Pearson <[email protected]>
+ Copyright (C) 2011 - 2015 Timothy Pearson <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -18,10 +18,12 @@
Boston, MA 02110-1301, USA.
*/
-#include "tdmtsak.h"
-
#include <tqstringlist.h>
+#include "dmctl.h"
+
+#include "tdmtsak.h"
+
#define FIFO_FILE "/tmp/tdesocket-global/tsak"
TQString exec(const char * cmd) {
@@ -44,15 +46,17 @@ bool is_vt_local() {
return false;
}
else {
- TQString cvtName = "";
- TQString output = exec("tdmctl list");
- TQStringList sessionList = TQStringList::split('\t', output, false);
- // See if the current session is local
- for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) {
- TQStringList sessionInfoList = TQStringList::split(',', *it, true);
- if ((*(sessionInfoList.at(0))).startsWith(":")) {
- if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) {
- return true;
+ DM dm;
+ SessList sess;
+ if (dm.localSessions(sess)) {
+ TQString user, loc;
+ for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
+ DM::sess2Str2(*it, user, loc);
+ TQStringList sessionInfoList = TQStringList::split(',', loc, true);
+ if ((*(sessionInfoList.at(0))).startsWith(":")) {
+ if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) {
+ return true;
+ }
}
}
}
@@ -68,44 +72,54 @@ bool is_vt_active() {
return true;
}
else {
+ DM dm;
+ SessList sess;
TQString cvtName = "";
- TQString output = exec("tdmctl list");
- TQString curConsole = exec("fgconsole");
- bool intFound;
- int curConsoleNum = curConsole.toInt(&intFound);
- if (intFound == false) {
+ TQString curConsole;
+ int curConsoleNum = dm.activeVT();
+ if (curConsoleNum < 0) {
return true;
}
- curConsole = TQString("vt%1").arg(curConsoleNum);;
- TQStringList sessionList = TQStringList::split('\t', output, false);
- for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) {
- TQStringList sessionInfoList = TQStringList::split(',', *it, true);
- if ((*(sessionInfoList.at(0))).startsWith(":")) {
- if ((*(sessionInfoList.at(1))) == TQString(curConsole)) {
- cvtName = (*(sessionInfoList.at(0)));
+ curConsole = TQString("vt%1").arg(curConsoleNum);
+ if (dm.localSessions(sess)) {
+ TQString user, loc;
+ for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
+ DM::sess2Str2(*it, user, loc);
+ TQStringList sessionInfoList = TQStringList::split(',', loc, true);
+ if ((*(sessionInfoList.at(0))).startsWith(":")) {
+ if ((*(sessionInfoList.at(1))).stripWhiteSpace() == TQString(curConsole)) {
+ cvtName = (*(sessionInfoList.at(0)));
+ }
}
}
- }
- if (cvtName != "") {
- if (TQString(currentDisplay).startsWith(cvtName)) {
- return true;
+ if (cvtName != "") {
+ if (TQString(currentDisplay).startsWith(cvtName)) {
+ return true;
+ }
+ else {
+ return false;
+ }
}
else {
- return false;
- }
- }
- else {
- // See if the current session is local
- // If it is, then the VT is not currently active and the SAK must be requested later when it is active
- for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) {
- TQStringList sessionInfoList = TQStringList::split(',', *it, true);
- if ((*(sessionInfoList.at(0))).startsWith(":")) {
- if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) {
- return false;
+ // See if the current session is local
+ // If it is, then the VT is not currently active and the SAK must be requested later when it is active
+ for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
+ DM::sess2Str2(*it, user, loc);
+ if ((*it).self) {
+ TQStringList sessionInfoList = TQStringList::split(',', loc, true);
+ if ((*(sessionInfoList.at(1))).startsWith(" vt")) {
+ // Local and inactive
+ return false;
+ }
}
}
+ // Hmm, not local
+ // Do not reject the SAK
+ return true;
}
- // Hmm, not local
+ }
+ else {
+ // Failure!
// Do not reject the SAK
return true;
}