• 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
indimenu.cpp
Go to the documentation of this file.
1 /* INDI frontend for KStars
2  Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
3  Elwood C. Downey
4 
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.
9 
10  JM Changelog:
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
18 
19  */
20 
21 #include "indimenu.h"
22 #include "indiproperty.h"
23 #include "indigroup.h"
24 #include "indidevice.h"
25 #include "devicemanager.h"
26 
27 #include <stdlib.h>
28 
29 #include <QLineEdit>
30 #include <QTextEdit>
31 #include <QFrame>
32 #include <QCheckBox>
33 #include <QLabel>
34 #include <QPushButton>
35 #include <QLayout>
36 #include <QSocketNotifier>
37 #include <QDateTime>
38 #include <QTimer>
39 
40 #include <KLed>
41 #include <KLineEdit>
42 #include <KPushButton>
43 #include <KLocale>
44 #include <KMessageBox>
45 #include <KDebug>
46 #include <KComboBox>
47 #include <KNumInput>
48 #include <KDialog>
49 #include <KTabWidget>
50 
51 #include "kstars.h"
52 #include "indidriver.h"
53 
54 /*******************************************************************
55 ** INDI Menu: Handles communication to server and fetching basic XML
56 ** data.
57 *******************************************************************/
58 INDIMenu::INDIMenu(QWidget *parent) : QWidget(parent, Qt::Window)
59 {
60 
61  ksw = (KStars *) parent;
62 
63  mainLayout = new QVBoxLayout(this);
64  mainLayout->setMargin(10);
65  mainLayout->setSpacing(10);
66 
67  mainTabWidget = new KTabWidget(this);
68 
69  mainLayout->addWidget(mainTabWidget);
70 
71  setWindowTitle(i18n("INDI Control Panel"));
72  setAttribute(Qt::WA_ShowModal, false);
73 
74  clearB = new QPushButton(i18n("Clear"));
75  closeB = new QPushButton(i18n("Close"));
76 
77  QHBoxLayout *buttonLayout = new QHBoxLayout;
78  buttonLayout->insertStretch(0);
79  buttonLayout->addWidget(clearB, 0, Qt::AlignRight);
80  buttonLayout->addWidget(closeB, 0, Qt::AlignRight);
81 
82  mainLayout->addLayout(buttonLayout);
83 
84  connect(closeB, SIGNAL(clicked()), this, SLOT(close()));
85  connect(clearB, SIGNAL(clicked()), this, SLOT(clearLog()));
86 
87  resize( 640, 480);
88 }
89 
90 INDIMenu::~INDIMenu()
91 {
92  while ( ! managers.isEmpty() ) delete managers.takeFirst();
93 }
94 
95 /*********************************************************************
96 ** Traverse the drivers list, check for updated drivers and take
97 ** appropriate action
98 *********************************************************************/
99 void INDIMenu::updateStatus()
100 {
101  if (managers.size() == 0)
102  {
103  KMessageBox::error(0, i18n("No INDI devices currently running. To run devices, please select devices from the Device Manager in the devices menu."));
104  return;
105  }
106 
107  show();
108 }
109 
110 DeviceManager* INDIMenu::initDeviceManager(QString inHost, uint inPort, DeviceManager::ManagerMode inMode)
111  {
112  DeviceManager *deviceManager;
113 
114  deviceManager = new DeviceManager(this, inHost, inPort, inMode);
115  managers.append(deviceManager);
116 
117  connect(deviceManager, SIGNAL(newDevice(INDI_D *)), ksw->indiDriver(), SLOT(enableDevice(INDI_D *)));
118  connect(deviceManager, SIGNAL(deviceManagerError(DeviceManager *)), this, SLOT(removeDeviceManager(DeviceManager*)), Qt::QueuedConnection);
119 
120  return deviceManager;
121 }
122 
123 void INDIMenu::stopDeviceManager(QList<IDevice *> &processed_devices)
124 {
125 
126  foreach(IDevice *device, processed_devices)
127  {
128  if (device->deviceManager != NULL)
129  removeDeviceManager(device->deviceManager);
130  }
131 }
132 
133 void INDIMenu::removeDeviceManager(DeviceManager *deviceManager)
134 {
135  if (deviceManager == NULL)
136  {
137  kWarning() << "Warning: trying to remove a null device manager detected.";
138  return;
139  }
140 
141  for (int i=0; i < managers.size(); i++)
142  {
143  if (deviceManager == managers.at(i))
144  {
145  foreach(INDI_D *device, deviceManager->indi_dev)
146  ksw->indiDriver()->disableDevice(device);
147 
148  delete managers.takeAt(i);
149  break;
150  }
151  }
152 
153  ksw->indiDriver()->updateMenuActions();
154 
155  if (managers.size() == 0)
156  close();
157 }
158 
159 INDI_D * INDIMenu::findDevice(const QString &deviceName)
160 {
161  for (int i=0; i < managers.size(); i++)
162  for (int j=0; j < managers[i]->indi_dev.size(); j++)
163  if (managers[i]->indi_dev[j]->name == deviceName)
164  return managers[i]->indi_dev[j];
165 
166  return NULL;
167 }
168 
169 INDI_D * INDIMenu::findDeviceByLabel(const QString &label)
170 {
171  for (int i=0; i < managers.size(); i++)
172  for (int j=0; j < managers[i]->indi_dev.size(); j++)
173  if (managers[i]->indi_dev[j]->label == label)
174  return managers[i]->indi_dev[j];
175 
176  return NULL;
177 }
178 
179 
180 QString INDIMenu::getUniqueDeviceLabel(const QString &deviceName)
181 {
182  int nset=0;
183 
184  for (int i=0; i < managers.size(); i++)
185  {
186  for (int j=0; j < managers[i]->indi_dev.size(); j++)
187  if (managers[i]->indi_dev[j]->label.indexOf(deviceName) >= 0)
188  nset++;
189  }
190 
191  if (nset)
192  return (deviceName + QString(" %1").arg(nset+1));
193  else
194  return (deviceName);
195 
196 }
197 
198 void INDIMenu::clearLog()
199 {
200  INDI_D *dev = findDeviceByLabel(mainTabWidget->tabText(mainTabWidget->currentIndex()).remove(QChar('&')));
201 
202  if (dev)
203  dev->msgST_w->clear();
204 
205 }
206 
207 
208 #include "indimenu.moc"
devicemanager.h
INDIMenu::clearLog
void clearLog()
Definition: indimenu.cpp:198
indimenu.h
INDIMenu::stopDeviceManager
void stopDeviceManager(QList< IDevice * > &processed_devices)
Definition: indimenu.cpp:123
INDIMenu::initDeviceManager
DeviceManager * initDeviceManager(QString inHost, uint inPort, DeviceManager::ManagerMode inMode)
Definition: indimenu.cpp:110
INDIMenu::INDIMenu
INDIMenu(QWidget *parent=0)
Definition: indimenu.cpp:58
QWidget
INDIMenu::findDeviceByLabel
INDI_D * findDeviceByLabel(const QString &label)
Definition: indimenu.cpp:169
indidevice.h
INDIMenu::~INDIMenu
~INDIMenu()
Definition: indimenu.cpp:90
INDIMenu::mainTabWidget
QTabWidget * mainTabWidget
Definition: indimenu.h:52
KStars
This is the main window for KStars.
Definition: kstars.h:94
INDIMenu::getUniqueDeviceLabel
QString getUniqueDeviceLabel(const QString &deviceName)
Definition: indimenu.cpp:180
INDI_D
Definition: indidevice.h:30
INDIMenu::findDevice
INDI_D * findDevice(const QString &deviceName)
Definition: indimenu.cpp:159
INDIMenu::updateStatus
void updateStatus()
Definition: indimenu.cpp:99
indidriver.h
INDIMenu::ksw
KStars * ksw
Definition: indimenu.h:44
INDIMenu::removeDeviceManager
void removeDeviceManager(DeviceManager *deviceManager)
Definition: indimenu.cpp:133
IDevice
Definition: indidriver.h:46
INDIMenu::managers
QList< DeviceManager * > managers
Definition: indimenu.h:46
IDevice::deviceManager
DeviceManager * deviceManager
Definition: indidriver.h:67
DeviceManager::indi_dev
QList< INDI_D * > indi_dev
Definition: devicemanager.h:38
INDIMenu::mainLayout
QVBoxLayout * mainLayout
Definition: indimenu.h:51
indiproperty.h
DeviceManager
Definition: devicemanager.h:27
DeviceManager::ManagerMode
ManagerMode
Definition: devicemanager.h:31
indigroup.h
kstars.h
QList
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