kstars
indimenu.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "indimenu.h"
00022 #include "indiproperty.h"
00023 #include "indigroup.h"
00024 #include "indidevice.h"
00025 #include "devicemanager.h"
00026
00027 #include <stdlib.h>
00028
00029 #include <qlineedit.h>
00030 #include <qtextedit.h>
00031 #include <qframe.h>
00032 #include <qtabwidget.h>
00033 #include <qcheckbox.h>
00034 #include <qlabel.h>
00035 #include <qpushbutton.h>
00036 #include <qlayout.h>
00037 #include <qsocketnotifier.h>
00038 #include <qdatetime.h>
00039 #include <qvbox.h>
00040 #include <qtimer.h>
00041
00042 #include <kled.h>
00043 #include <klineedit.h>
00044 #include <klistbox.h>
00045 #include <kpushbutton.h>
00046 #include <kapplication.h>
00047 #include <klocale.h>
00048 #include <kmessagebox.h>
00049 #include <klistview.h>
00050 #include <kdebug.h>
00051 #include <kcombobox.h>
00052 #include <knuminput.h>
00053 #include <kdialogbase.h>
00054
00055 #include "kstars.h"
00056 #include "indidriver.h"
00057
00058
00059
00060
00061
00062 INDIMenu::INDIMenu(QWidget *parent, const char *name ) : KDialogBase(KDialogBase::Tabbed, i18n("INDI Control Panel"), 0, KDialogBase::Default, parent, name, false)
00063 {
00064
00065 ksw = (KStars *) parent;
00066
00067 mgrCounter = 0;
00068
00069 mgr.setAutoDelete(true);
00070
00071 currentLabel = "";
00072
00073 resize( 640, 480);
00074 }
00075
00076 INDIMenu::~INDIMenu()
00077 {
00078 mgr.clear();
00079 }
00080
00081
00082
00083
00084
00085 void INDIMenu::updateStatus()
00086 {
00087 INDIDriver *drivers = ksw->getINDIDriver();
00088
00089
00090 processServer();
00091
00092 if (drivers)
00093 {
00094 if (drivers->activeDriverCount() == 0)
00095 {
00096 KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
00097 return;
00098 }
00099 }
00100 else if (mgr.count() == 0)
00101 {
00102 KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
00103 return;
00104 }
00105
00106 show();
00107
00108 }
00109
00110 bool INDIMenu::processServer()
00111 {
00112
00113 INDIDriver *drivers = ksw->getINDIDriver();
00114 DeviceManager *dev;
00115
00116 if (drivers == NULL)
00117 return false;
00118
00119 for (unsigned int i=0; i < drivers->devices.size(); i++)
00120 {
00121
00122 if (drivers->devices[i]->state && drivers->devices[i]->managed == false && drivers->devices[i]->mode == IDevice::M_LOCAL)
00123 {
00124 dev = new DeviceManager(this, mgrCounter);
00125 if (dev->indiConnect("localhost", QString("%1").arg(drivers->devices[i]->indiPort)))
00126 {
00127 drivers->devices[i]->mgrID = mgrCounter;
00128 drivers->devices[i]->managed = true;
00129 mgr.append(dev);
00130 connect(dev, SIGNAL(newDevice()), drivers, SLOT(updateMenuActions()));
00131 connect(dev, SIGNAL(newDevice()), this, SLOT(discoverDevice()));
00132
00133 mgrCounter++;
00134
00135 }
00136 else
00137 {
00138 delete (dev);
00139 return false;
00140 }
00141 }
00142
00143 else if (!drivers->devices[i]->state && drivers->devices[i]->managed == true && drivers->devices[i]->mode == IDevice::M_LOCAL)
00144 {
00145 drivers->devices[i]->managed = false;
00146 removeDeviceMgr(drivers->devices[i]->mgrID);
00147 return true;
00148
00149 }
00150 }
00151
00152 return true;
00153
00154 }
00155
00156 int INDIMenu::processClient(QString hostname, QString portnumber)
00157 {
00158
00159 DeviceManager *dev;
00160 INDIDriver *drivers = ksw->getINDIDriver();
00161
00162 dev = new DeviceManager(this, mgrCounter);
00163 if (dev->indiConnect(hostname, portnumber))
00164 {
00165 mgr.append(dev);
00166 if (drivers)
00167 {
00168 connect(dev, SIGNAL(newDevice()), drivers, SLOT(updateMenuActions()));
00169 connect(dev, SIGNAL(newDevice()), this, SLOT(discoverDevice()));
00170 }
00171 }
00172 else
00173 {
00174 delete (dev);
00175 return (-1);
00176 }
00177
00178 mgrCounter++;
00179 return (mgrCounter - 1);
00180 }
00181
00182 void INDIMenu::removeDeviceMgr(int mgrID)
00183 {
00184
00185 for (unsigned int i=0; i < mgr.count(); i++)
00186 {
00187 if (mgrID == mgr.at(i)->mgrID)
00188 mgr.remove(i);
00189
00190 emit driverDisconnected(mgrID);
00191 }
00192 }
00193
00194 INDI_D * INDIMenu::findDevice(QString deviceName)
00195 {
00196 for (unsigned int i=0; i < mgr.count(); i++)
00197 {
00198 for (unsigned int j=0; j < mgr.at(i)->indi_dev.count(); j++)
00199 if (mgr.at(i)->indi_dev.at(j)->name == deviceName)
00200 return mgr.at(i)->indi_dev.at(j);
00201 }
00202 return NULL;
00203 }
00204
00205 INDI_D * INDIMenu::findDeviceByLabel(QString label)
00206 {
00207 for (unsigned int i=0; i < mgr.count(); i++)
00208 {
00209 for (unsigned int j=0; j < mgr.at(i)->indi_dev.count(); j++)
00210 if (mgr.at(i)->indi_dev.at(j)->label == label)
00211 return mgr.at(i)->indi_dev.at(j);
00212 }
00213
00214 return NULL;
00215 }
00216
00217
00218 void INDIMenu::setCustomLabel(QString deviceName)
00219 {
00220
00221 int nset=0;
00222
00223 for (unsigned int i=0; i < mgr.count(); i++)
00224 for (unsigned int j=0; j < mgr.at(i)->indi_dev.count(); j++)
00225 if (mgr.at(i)->indi_dev.at(j)->label.find(deviceName) >= 0)
00226 nset++;
00227
00228 if (nset)
00229 currentLabel = deviceName + QString(" %1").arg(nset+1);
00230 else
00231 currentLabel = deviceName;
00232
00233 }
00234
00235 void INDIMenu::discoverDevice()
00236 {
00237 QTimer::singleShot( 1000, this, SLOT(announceDevice()) );
00238 }
00239
00240 void INDIMenu::announceDevice()
00241 {
00242 newDevice();
00243 }
00244
00245
00246
00247 #include "indimenu.moc"