1 /* INDI frontend for KStars
2 Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
5 This application is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
11 2003-04-28 Used indimenu.c as a template. C --> C++, Xm --> KDE/Qt
12 2003-05-01 Added tab for devices and a group feature
13 2003-05-02 Added scrolling area. Most things are rewritten
14 2003-05-05 Adding INDI Conf
15 2003-05-06 Drivers XML reader
16 2003-05-07 Device manager integration
17 2003-05-21 Full client support
22 #include "indiproperty.h"
23 #include "indigroup.h"
24 #include "indidevice.h"
25 #include "devicemanager.h"
29 #include <qlineedit.h>
30 #include <qtextedit.h>
32 #include <qtabwidget.h>
33 #include <qcheckbox.h>
35 #include <qpushbutton.h>
37 #include <qsocketnotifier.h>
38 #include <qdatetime.h>
43 #include <klineedit.h>
45 #include <kpushbutton.h>
46 #include <kapplication.h>
48 #include <kmessagebox.h>
49 #include <klistview.h>
51 #include <kcombobox.h>
52 #include <knuminput.h>
53 #include <kdialogbase.h>
56 #include "indidriver.h"
58 /*******************************************************************
59 ** INDI Menu: Handles communication to server and fetching basic XML
61 *******************************************************************/
62 INDIMenu::INDIMenu(QWidget
*parent
, const char *name
) : KDialogBase(KDialogBase::Tabbed
, i18n("INDI Control Panel"), 0, KDialogBase::Default
, parent
, name
, false)
65 ksw
= (KStars
*) parent
;
69 mgr
.setAutoDelete(true);
81 /*********************************************************************
82 ** Traverse the drivers list, check for updated drivers and take
84 *********************************************************************/
85 void INDIMenu::updateStatus()
87 INDIDriver
*drivers
= ksw
->getINDIDriver();
94 if (drivers
->activeDriverCount() == 0)
96 KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
100 else if (mgr
.count() == 0)
102 KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
110 bool INDIMenu::processServer()
113 INDIDriver
*drivers
= ksw
->getINDIDriver();
119 for (unsigned int i
=0; i
< drivers
->devices
.size(); i
++)
121 // Devices ready to run but not yet managed
122 if (drivers
->devices
[i
]->state
&& drivers
->devices
[i
]->managed
== false && drivers
->devices
[i
]->mode
== IDevice::M_LOCAL
)
124 dev
= new DeviceManager(this, mgrCounter
);
125 if (dev
->indiConnect("localhost", QString("%1").arg(drivers
->devices
[i
]->indiPort
)))
127 drivers
->devices
[i
]->mgrID
= mgrCounter
;
128 drivers
->devices
[i
]->managed
= true;
130 connect(dev
, SIGNAL(newDevice()), drivers
, SLOT(updateMenuActions()));
131 connect(dev
, SIGNAL(newDevice()), this, SLOT(discoverDevice()));
142 // Devices running and they need to be shutdown
143 else if (!drivers
->devices
[i
]->state
&& drivers
->devices
[i
]->managed
== true && drivers
->devices
[i
]->mode
== IDevice::M_LOCAL
)
145 drivers
->devices
[i
]->managed
= false;
146 removeDeviceMgr(drivers
->devices
[i
]->mgrID
);
156 int INDIMenu::processClient(QString hostname
, QString portnumber
)
160 INDIDriver
*drivers
= ksw
->getINDIDriver();
162 dev
= new DeviceManager(this, mgrCounter
);
163 if (dev
->indiConnect(hostname
, portnumber
))
168 connect(dev
, SIGNAL(newDevice()), drivers
, SLOT(updateMenuActions()));
169 connect(dev
, SIGNAL(newDevice()), this, SLOT(discoverDevice()));
179 return (mgrCounter
- 1);
182 void INDIMenu::removeDeviceMgr(int mgrID
)
185 for (unsigned int i
=0; i
< mgr
.count(); i
++)
187 if (mgrID
== mgr
.at(i
)->mgrID
)
190 emit
driverDisconnected(mgrID
);
194 INDI_D
* INDIMenu::findDevice(QString deviceName
)
196 for (unsigned int i
=0; i
< mgr
.count(); i
++)
198 for (unsigned int j
=0; j
< mgr
.at(i
)->indi_dev
.count(); j
++)
199 if (mgr
.at(i
)->indi_dev
.at(j
)->name
== deviceName
)
200 return mgr
.at(i
)->indi_dev
.at(j
);
205 INDI_D
* INDIMenu::findDeviceByLabel(QString label
)
207 for (unsigned int i
=0; i
< mgr
.count(); i
++)
209 for (unsigned int j
=0; j
< mgr
.at(i
)->indi_dev
.count(); j
++)
210 if (mgr
.at(i
)->indi_dev
.at(j
)->label
== label
)
211 return mgr
.at(i
)->indi_dev
.at(j
);
218 void INDIMenu::setCustomLabel(QString deviceName
)
223 for (unsigned int i
=0; i
< mgr
.count(); i
++)
224 for (unsigned int j
=0; j
< mgr
.at(i
)->indi_dev
.count(); j
++)
225 if (mgr
.at(i
)->indi_dev
.at(j
)->label
.find(deviceName
) >= 0)
229 currentLabel
= deviceName
+ QString(" %1").arg(nset
+1);
231 currentLabel
= deviceName
;
235 void INDIMenu::discoverDevice()
237 QTimer::singleShot( 1000, this, SLOT(announceDevice()) );
240 void INDIMenu::announceDevice()
247 #include "indimenu.moc"