summaryrefslogtreecommitdiffstats
path: root/src/knutinstcomms.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-19 18:17:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-19 18:17:02 +0000
commitf867212c1762e156553d039319b904a17f7b563d (patch)
tree461c1a743b3ff8291e03360742dbbfb4cc0087e4 /src/knutinstcomms.cpp
downloadknutclient-f867212c1762e156553d039319b904a17f7b563d.tar.gz
knutclient-f867212c1762e156553d039319b904a17f7b563d.zip
Added KDE3 version of knutclient
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/knutclient@1092914 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/knutinstcomms.cpp')
-rwxr-xr-xsrc/knutinstcomms.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/knutinstcomms.cpp b/src/knutinstcomms.cpp
new file mode 100755
index 0000000..e21ebfc
--- /dev/null
+++ b/src/knutinstcomms.cpp
@@ -0,0 +1,137 @@
+/***************************************************************************
+ knutinstcomms.cpp - description
+ -------------------
+ begin : ct ríj 24 2002
+ copyright : (C) 2002 by Daniel Prynych
+ email : Daniel.Prynych@alo.cz
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "knutinstcomms.h"
+#include "knutprintupsvar.h"
+#include "knutvardata.h"
+
+#include <kcombobox.h>
+#include <kmessagebox.h>
+
+
+#include <qlayout.h>
+#include <qframe.h>
+#include <qlabel.h>
+#include <qstring.h>
+
+
+KNutInstComms::KNutInstComms(QString* userName, QString* userPassword, const QString uName, const QString password, KNutNet* const upsNet, QWidget* parent, const char* name, const bool modal)
+: KDialogBase(Plain, i18n("Instant commands"),Ok|Cancel,Ok, parent, name, modal, true), m_upsNet(upsNet),m_oldUserName(userName), m_oldUserPassword(userPassword) {
+ upsICommDef upsIComm;
+
+
+ if (m_upsNet->getState() != KNutNet::Connected) { // no connection - no instant commnads
+ KNutVarData::showError (KNutNet::NotConnection);
+ m_upsConnectOk=false;
+ }
+ else {
+ m_upsConnectOk=true;
+ QFrame *page = plainPage();
+ QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
+ QLabel *label1 = new QLabel (i18n("RUN INSTANT COMMAND"),page,"label1");
+ label1->setAlignment(Qt::AlignHCenter);
+ topLayout->addWidget(label1);
+
+ QLabel *label2 = new QLabel (i18n("Command:"),page,"label2");
+ m_instCommBox = new KComboBox(page,"instcommbox");
+
+ QGridLayout *passLayout = new QGridLayout (3,2,5,"passLayout");
+ QLabel *labelName = new QLabel (i18n("User name:"),page,"labelName");
+ QLabel *labelPassword = new QLabel (i18n("Password:"),page,"labelPassword");
+ m_lineEditName = new KLineEdit( page, "LineEditName" );
+ m_lineEditPassword = new KLineEdit( page, "LineEditName" );
+ if (((*m_oldUserName) == "") && ((*m_oldUserPassword) == "")) {
+ m_lineEditName->setText(uName);
+ m_lineEditPassword->setText(password);
+ }
+ else {
+ m_lineEditName->setText(*m_oldUserName);
+ m_lineEditPassword->setText(*m_oldUserPassword);
+ m_lineEditName->setDisabled(true);
+ m_lineEditPassword->setDisabled(true);
+ }
+
+ // if (!((*oldUserName) == "") || !((*oldUserPassword) == "")) {
+ // if (!((*oldUserName) == "") && ((*oldUserPassword) == "")) {
+ // lineEditName->setDisabled(true);
+ // lineEditPassword->setDisabled(true);
+ // }
+
+ m_lineEditPassword->setEchoMode(QLineEdit::Password);
+
+ topLayout->addLayout(passLayout);
+
+ passLayout->addWidget(label2,0,0);
+ passLayout->addWidget(m_instCommBox,0,1);
+
+ passLayout->addWidget(labelName,1,0);
+ passLayout->addWidget(labelPassword,2,0);
+ passLayout->addWidget(m_lineEditName,1,1);
+ passLayout->addWidget(m_lineEditPassword,2,1);
+
+ topLayout->addStretch(10);
+
+ //loads ComboBox
+ int n = m_upsNet->readNumberComms()+1;
+ for (int i =1; i < n ; i++) { // for se testuje na zacatku pokud je n < 1 neprovede se ani jednou
+ if (!m_upsNet->readIComm(i, upsIComm))
+ m_instCommBox->insertItem(upsIComm.upsCommName);
+ }
+ }
+ }
+
+KNutInstComms::~KNutInstComms(){
+}
+
+
+void KNutInstComms::slotOk() {
+ int error =0;
+
+
+ if (((*m_oldUserName) == "") && ((*m_oldUserPassword) == "")) {
+ // prvni propojeni nastavime jmeno a heslo
+ //for the first connection we have to set name and password
+ if (!( error = m_upsNet->instantCommand(m_instCommBox->currentText(),m_lineEditName->text(),m_lineEditPassword->text(),false))) {
+ (*m_oldUserName) = m_lineEditName->text();
+ (*m_oldUserPassword) = m_lineEditPassword->text();
+ accept();
+ }
+ }
+ else {
+ // for other connection name and password are not setted
+ if (((*m_oldUserName) == m_lineEditName->text()) && ((*m_oldUserPassword) == m_lineEditPassword->text())) {
+ // jen posleme prikaz // sends command only
+ if (!( error = m_upsNet->instantCommand(m_instCommBox->currentText(),m_lineEditName->text(),m_lineEditPassword->text(),true))) accept();
+ }
+// az v pristi verzi
+// else
+// {
+// // odpojime a pripojime
+// // nastavime jmeno a heslo
+// if (!( error = myUpsNet->instantCommand(instCommBox->currentText(),lineEditName->text(),lineEditPassword->text(),false))) {
+// (*oldUserName) = lineEditName->text();
+// (*oldUserPassword) = lineEditPassword->text();
+// accept();
+// }
+// }
+ }
+ if (error) KNutVarData::showError (error);
+ }
+
+//bool KNutInstComms::upsOk (void) { return m_upsConnectOk; }
+
+