• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • indi
guimanager.cpp
Go to the documentation of this file.
1 /* INDI frontend for KStars
2  Copyright (C) 2012 Jasem Mutlaq
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8  */
9 
10 #include <stdlib.h>
11 
12 #include <QLineEdit>
13 #include <QTextEdit>
14 #include <QFrame>
15 #include <QCheckBox>
16 #include <QLabel>
17 #include <QPushButton>
18 #include <QLayout>
19 #include <QSocketNotifier>
20 #include <QDateTime>
21 #include <QTimer>
22 #include <QSplitter>
23 
24 #include <KLed>
25 #include <KLineEdit>
26 #include <KPushButton>
27 #include <KLocale>
28 #include <KMessageBox>
29 #include <KDebug>
30 #include <KComboBox>
31 #include <KNumInput>
32 #include <KDialog>
33 #include <KTabWidget>
34 
35 #include <basedevice.h>
36 
37 #include "kstars.h"
38 #include "indidevice.h"
39 #include "guimanager.h"
40 #include "driverinfo.h"
41 #include "deviceinfo.h"
42 
43 extern const char *libindi_strings_context;
44 
45 GUIManager * GUIManager::_GUIManager = NULL;
46 
47 GUIManager * GUIManager::Instance()
48 {
49  if (_GUIManager == NULL)
50  _GUIManager = new GUIManager(KStars::Instance());
51 
52  return _GUIManager;
53 }
54 
55 GUIManager::GUIManager(QWidget *parent) : QWidget(parent, Qt::Window)
56 {
57 
58  //ksw = (KStars *) parent;
59 
60  mainLayout = new QVBoxLayout(this);
61  mainLayout->setMargin(10);
62  mainLayout->setSpacing(10);
63 
64  mainTabWidget = new KTabWidget(this);
65 
66  mainLayout->addWidget(mainTabWidget);
67 
68  setWindowTitle(i18n("INDI Control Panel"));
69  setAttribute(Qt::WA_ShowModal, false);
70 
71  clearB = new QPushButton(i18n("Clear"));
72  closeB = new QPushButton(i18n("Close"));
73 
74  QHBoxLayout *buttonLayout = new QHBoxLayout;
75  buttonLayout->insertStretch(0);
76  buttonLayout->addWidget(clearB, 0, Qt::AlignRight);
77  buttonLayout->addWidget(closeB, 0, Qt::AlignRight);
78 
79  mainLayout->addLayout(buttonLayout);
80 
81  connect(closeB, SIGNAL(clicked()), this, SLOT(close()));
82  connect(clearB, SIGNAL(clicked()), this, SLOT(clearLog()));
83 
84  resize( 640, 480);
85 }
86 
87 /*********************************************************************
88 ** Traverse the drivers list, check for updated drivers and take
89 ** appropriate action
90 *********************************************************************/
91 void GUIManager::updateStatus()
92 {
93  if (clients.size() == 0)
94  {
95  KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
96  return;
97  }
98 
99  show();
100 }
101 
102 INDI_D * GUIManager::findGUIDevice(const QString &deviceName)
103 {
104 
105  foreach(INDI_D *gdv, guidevices)
106  {
107  if (gdv->getBaseDevice()->getDeviceName() == deviceName)
108  return gdv;
109  }
110 
111  return NULL;
112 }
113 
114 
115 void GUIManager::clearLog()
116 {
117 
118  INDI_D *dev = findGUIDevice(mainTabWidget->tabText(mainTabWidget->currentIndex()).remove(QChar('&')));
119 
120  if (dev)
121  dev->clearMessageLog();
122 
123 }
124 
125 void GUIManager::addClient(ClientManager *cm)
126 {
127  clients.append(cm);
128 
129 
130  connect(cm, SIGNAL(newINDIDevice(DeviceInfo*)), this, SLOT(buildDevice(DeviceInfo*)), Qt::BlockingQueuedConnection);
131 
132  connect(cm, SIGNAL(INDIDeviceRemoved(DeviceInfo*)), this, SLOT(removeDevice(DeviceInfo*)));
133 
134  //INDI_D *gdm = new INDI_D(this, cm);
135 
136  //connect(cm, SIGNAL(newINDIProperty(INDI::Property*)), gdm, SLOT(buildProperty(INDI::Property*)));
137 
138  //guidevices.append(gdm);
139 
140  updateStatus();
141 }
142 
143 void GUIManager::removeClient(ClientManager *cm)
144 {
145  clients.removeOne(cm);
146 
147  for (int i=0; i < guidevices.size(); i++)
148  guidevices.at(i)->setTabID(i);
149 
150  foreach(INDI_D *gdv, guidevices)
151  {
152  //qDebug() << "Terminating client.... " << endl;
153  if (gdv->getClientManager() == cm)
154  {
155  //qDebug() << "Will remove device " << gdv->getBaseDevice()->getDeviceName() << " with tab ID " << gdv->getTabID() << endl;
156  mainTabWidget->removeTab(gdv->getTabID());
157  guidevices.removeOne(gdv);
158  delete (gdv);
159  break;
160  }
161  }
162 
163  if (clients.size() == 0)
164  hide();
165 }
166 
167 void GUIManager::removeDevice(DeviceInfo *di)
168 {
169  INDI_D *dp=NULL;
170 
171  dp = findGUIDevice(di->getDriverInfo()->getUniqueLabel());
172 
173  if (dp == NULL)
174  return;
175 
176  mainTabWidget->removeTab(dp->getTabID());
177  guidevices.removeOne(dp);
178  delete (dp);
179 
180  // rearrange tab indexes
181  for (int i=0; i < guidevices.size(); i++)
182  guidevices.at(i)->setTabID(i);
183 }
184 
185 void GUIManager::buildDevice(DeviceInfo *di)
186 {
187  //qDebug() << "In build Device for device with tree label " << di->getTreeLabel() << endl;
188  int nset=0;
189  ClientManager *cm = di->getDriverInfo()->getClientManager();
190 
191  if (cm == NULL)
192  {
193  qDebug() << "Error clientManager is null in build device!" << endl;
194  return;
195 
196  }
197 
198  INDI_D *gdm = new INDI_D(this, di->getBaseDevice(), cm);
199 
200  connect(cm, SIGNAL(newINDIProperty(INDI::Property*)), gdm, SLOT(buildProperty(INDI::Property*)));
201  connect(cm, SIGNAL(removeINDIProperty(INDI::Property*)), gdm, SLOT(removeProperty(INDI::Property*)), Qt::BlockingQueuedConnection);
202  connect(cm, SIGNAL(newINDISwitch(ISwitchVectorProperty*)), gdm, SLOT(updateSwitchGUI(ISwitchVectorProperty*)));
203  connect(cm, SIGNAL(newINDIText(ITextVectorProperty*)), gdm, SLOT(updateTextGUI(ITextVectorProperty*)));
204  connect(cm, SIGNAL(newINDINumber(INumberVectorProperty*)), gdm, SLOT(updateNumberGUI(INumberVectorProperty*)));
205  connect(cm, SIGNAL(newINDILight(ILightVectorProperty*)), gdm, SLOT(updateLightGUI(ILightVectorProperty*)));
206  connect(cm, SIGNAL(newINDIBLOB(IBLOB*)), gdm, SLOT(updateBLOBGUI(IBLOB*)));
207 
208  connect(cm, SIGNAL(newINDIMessage(INDI::BaseDevice*, int)), gdm, SLOT(updateMessageLog(INDI::BaseDevice*, int)));
209 
210 
211  //qDebug() << "About to add to tab main widget with name " << di->getBaseDevice()->getDeviceName() << endl;
212  //nset = mainTabWidget->addTab(gdm->getDeviceBox(), di->getBaseDevice()->getDeviceName());
213  nset = mainTabWidget->addTab(gdm->getDeviceBox(), i18nc(libindi_strings_context, di->getDriverInfo()->getUniqueLabel().toUtf8()));
214 
215  gdm->setTabID(nset);
216 
217  guidevices.append(gdm);
218 
219 
220 
221 }
222 
223 
224 #include "guimanager.moc"
GUIManager::clearLog
void clearLog()
Definition: guimanager.cpp:115
GUIManager::buildDevice
void buildDevice(DeviceInfo *di)
Definition: guimanager.cpp:185
deviceinfo.h
INDI_D::clearMessageLog
void clearMessageLog()
Definition: indidevice.cpp:307
INDI_D::setTabID
void setTabID(int newTabID)
Definition: indidevice.h:42
QWidget
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
indidevice.h
DeviceInfo::getBaseDevice
INDI::BaseDevice * getBaseDevice()
Definition: deviceinfo.h:24
guimanager.h
INDI_D::getTabID
int getTabID()
Definition: indidevice.h:43
DriverInfo::getClientManager
ClientManager * getClientManager()
Definition: driverinfo.h:61
INDI_D::getBaseDevice
INDI::BaseDevice * getBaseDevice()
Definition: indidevice.h:49
driverinfo.h
DriverInfo::getUniqueLabel
const QString & getUniqueLabel()
Definition: driverinfo.h:43
INDI_D
Definition: indidevice.h:30
DeviceInfo::getDriverInfo
DriverInfo * getDriverInfo()
Definition: deviceinfo.h:23
GUIManager::addClient
void addClient(ClientManager *cm)
Definition: guimanager.cpp:125
INDI_D::getDeviceBox
QSplitter * getDeviceBox()
Definition: indidevice.h:40
i18nc
i18nc("string from libindi, used in the config dialog","100x")
GUIManager::removeClient
void removeClient(ClientManager *cm)
Definition: guimanager.cpp:143
GUIManager::Instance
static GUIManager * Instance()
Definition: guimanager.cpp:47
ClientManager
Definition: clientmanager.h:22
INDI_D::getClientManager
ClientManager * getClientManager()
Definition: indidevice.h:45
libindi_strings_context
const char * libindi_strings_context
Definition: indidevice.cpp:54
GUIManager::updateStatus
void updateStatus()
Definition: guimanager.cpp:91
DeviceInfo
Definition: deviceinfo.h:18
GUIManager::findGUIDevice
INDI_D * findGUIDevice(const QString &deviceName)
Definition: guimanager.cpp:102
kstars.h
GUIManager
Definition: guimanager.h:46
GUIManager::removeDevice
void removeDevice(DeviceInfo *di)
Definition: guimanager.cpp:167
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal