[Kstars-devel] KDE/kdeedu/kstars/kstars

Jasem Mutlaq mutlaqja at ikarustech.com
Mon Oct 11 23:23:21 CEST 2010


SVN commit 1184932 by mutlaqja:

Enable user to pre-select a port for each device in the device manager.

CCMAIL:kstars-devel at kde.org


 M  +62 -32    indi/indidriver.cpp  
 M  +6 -0      indi/indidriver.h  
 M  +0 -1      tools/lcgenerator.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/indi/indidriver.cpp #1184931:1184932
@@ -76,8 +76,17 @@
     connected           = KIcon( "network-connect" );
     disconnected        = KIcon( "network-disconnect" );
 
+    connect(localTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(makePortEditable(QTreeWidgetItem*,int)));
+
 }
 
+void DeviceManagerUI::makePortEditable(QTreeWidgetItem* selectedItem, int column)
+{
+    // If it's the port column, then make it user-editable
+    if (column == INDIDriver::LOCAL_PORT_COLUMN)
+        selectedItem->setFlags(Qt::ItemIsEditable);
+}
+
 INDIDriver::INDIDriver( KStars *_ks )
         : KDialog( _ks ),  ksw( _ks )
 {
@@ -95,9 +104,9 @@
     {
         QTreeWidgetItem *item = new QTreeWidgetItem(ui->clientTreeWidget, lastGroup);
         lastGroup = item;
-        item->setIcon(0, ui->disconnected);
-        item->setText(1, host->name);
-        item->setText(2, host->portnumber);
+        item->setIcon(HOST_STATUS_COLUMN, ui->disconnected);
+        item->setText(HOST_NAME_COLUMN, host->name);
+        item->setText(HOST_PORT_COLUMN, host->portnumber);
     }
 
     lastGroup = NULL;
@@ -131,7 +140,7 @@
 	        if (host->deviceManager == indi_device->deviceManager && host->isConnected == false)
 	        {
 	    		foreach (QTreeWidgetItem *item, ui->clientTreeWidget->findItems(host->name, Qt::MatchExactly, 1))
-				item->setIcon(0, ui->connected);
+                                item->setIcon(HOST_STATUS_COLUMN, ui->connected);
 	
              		host->isConnected = true;
 			updateClientTab();
@@ -149,8 +158,8 @@
 		{
 			foreach (QTreeWidgetItem *item, ui->localTreeWidget->findItems(device->tree_label, Qt::MatchExactly |  Qt::MatchRecursive))
 			{
-				item->setIcon(1, ui->runningPix);
-        			item->setText(4, QString::number(indi_device->deviceManager->port));
+                                item->setIcon(LOCAL_STATUS_COLUMN, ui->runningPix);
+                                item->setText(LOCAL_PORT_COLUMN, QString::number(indi_device->deviceManager->port));
 			}
 			
 			updateLocalTab();
@@ -175,7 +184,7 @@
 	        if (host->deviceManager == indi_device->deviceManager && host->isConnected == true)
 	        {
 	    		foreach (QTreeWidgetItem *item, ui->clientTreeWidget->findItems(host->name, Qt::MatchExactly,1))
-				item->setIcon(0, ui->disconnected);
+                                item->setIcon(HOST_STATUS_COLUMN, ui->disconnected);
 	
 			host->deviceManager = NULL;
 		        host->isConnected = false;
@@ -193,9 +202,9 @@
 		{
 			foreach (QTreeWidgetItem *item, ui->localTreeWidget->findItems(device->tree_label, Qt::MatchExactly |  Qt::MatchRecursive))
 			{
-				item->setIcon(1, ui->stopPix);
-            			item->setIcon(2, QIcon());
-            			item->setText(4, QString());
+                                item->setIcon(LOCAL_STATUS_COLUMN, ui->stopPix);
+                                item->setIcon(LOCAL_MODE_COLUMN, QIcon());
+                                item->setText(LOCAL_PORT_COLUMN, QString());
 			}
 			
 			device->clear();
@@ -236,7 +245,7 @@
     foreach (IDevice *device, devices)
       {
   
-        if (ui->localTreeWidget->currentItem()->text(0) == device->tree_label)
+        if (ui->localTreeWidget->currentItem()->text(LOCAL_NAME_COLUMN) == device->tree_label)
           {
             ui->runServiceB->setEnabled(device->state == IDevice::DEV_TERMINATE);
             ui->stopServiceB->setEnabled(device->state == IDevice::DEV_START);
@@ -256,7 +265,7 @@
 
     foreach (INDIHostsInfo * host, ksw->data()->INDIHostsList)
     {
-        if (ui->clientTreeWidget->currentItem()->text(1) == host->name && ui->clientTreeWidget->currentItem()->text(2) == host->portnumber)
+        if (ui->clientTreeWidget->currentItem()->text(HOST_NAME_COLUMN) == host->name && ui->clientTreeWidget->currentItem()->text(HOST_PORT_COLUMN) == host->portnumber)
         {
             ui->connectHostB->setEnabled(!host->isConnected);
             ui->disconnectHostB->setEnabled(host->isConnected);
@@ -271,24 +280,45 @@
    QList<IDevice *> processed_devices;
    DeviceManager *deviceManager=NULL;
 
+   int port=0;
+   bool portOK=false;
+
    foreach(QTreeWidgetItem *item, ui->localTreeWidget->selectedItems())
    {
       foreach (IDevice *device, devices)
       {
 		//device->state = (dev_request == IDevice::DEV_TERMINATE) ? IDevice::DEV_START : IDevice::DEV_TERMINATE;
-		if (item->text(0) == device->tree_label && device->state != dev_request)
+                if (item->text(LOCAL_NAME_COLUMN) == device->tree_label && device->state != dev_request)
+                {
+			processed_devices.append(device);
 
-			processed_devices.append(device);
+                        // N.B. If multipe devices are selected to run under one device manager
+                        // then we select the port for the first device that has a valid port
+                        // entry, the rest are ignored.
+                        if (port != 0 && item->text(LOCAL_PORT_COLUMN).isEmpty() == false)
+                        {
+                            port = item->text(LOCAL_PORT_COLUMN).toInt(&portOK);
+                            // If we encounter conversion error, we abort
+                            if (portOK == false)
+                            {
+                                KMessageBox::error(0, i18n("Invalid port entry: %1", item->text(LOCAL_PORT_COLUMN)));
+                                return;
       }
    }
+                }
+       }
+   }
 
    if (processed_devices.empty()) return;
 
+   // Select random port within range is none specified.
+   if (port == 0)
+       port = getINDIPort();
+
    if (dev_request == IDevice::DEV_START)
    {
-	int port = getINDIPort();
 
-    	if (port < 0)
+        if (port <= 0)
         {
 	        KMessageBox::error(0, i18n("Cannot start INDI server: port error."));
         	return;
@@ -321,7 +351,7 @@
 
     foreach (INDIHostsInfo * host, ksw->data()->INDIHostsList)
         //hostInfo = ksw->data()->INDIHostsList.at(i);
-        if (currentItem->text(1) == host->name && currentItem->text(2) == host->portnumber)
+        if (currentItem->text(HOST_NAME_COLUMN) == host->name && currentItem->text(HOST_PORT_COLUMN) == host->portnumber)
         {
             // Nothing changed, return
             if (host->isConnected == toConnect)
@@ -643,9 +673,9 @@
         QTreeWidgetItem *device = new QTreeWidgetItem(DGroup, lastDevice);
 
 
-    device->setText(0, QString(label));
-    device->setIcon(1, ui->stopPix);
-    device->setText(3, QString(version));
+    device->setText(LOCAL_NAME_COLUMN, QString(label));
+    device->setIcon(LOCAL_STATUS_COLUMN, ui->stopPix);
+    device->setText(LOCAL_VERSION_COLUMN, QString(version));
 
     lastDevice = device;
 
@@ -703,9 +733,9 @@
             version = QString("1.0");
 
             QTreeWidgetItem *device = new QTreeWidgetItem(group, lastDevice);
-            device->setText(0, QString(label));
-            device->setIcon(1, ui->stopPix);
-            device->setText(3, QString(version));
+            device->setText(LOCAL_NAME_COLUMN, QString(label));
+            device->setIcon(LOCAL_STATUS_COLUMN, ui->stopPix);
+            device->setText(LOCAL_VERSION_COLUMN, QString(version));
 
             lastDevice = device;
 
@@ -783,9 +813,9 @@
         ksw->data()->INDIHostsList.append(hostItem);
 
         QTreeWidgetItem *item = new QTreeWidgetItem(ui->clientTreeWidget);
-        item->setIcon(0, ui->disconnected);
-        item->setText(1, hostConf.nameIN->text());
-        item->setText(2, hostConf.portnumber->text());
+        item->setIcon(HOST_STATUS_COLUMN, ui->disconnected);
+        item->setText(HOST_NAME_COLUMN, hostConf.nameIN->text());
+        item->setText(HOST_PORT_COLUMN, hostConf.portnumber->text());
 
     }
 
@@ -809,7 +839,7 @@
 
     foreach (INDIHostsInfo * host, ksw->data()->INDIHostsList)
     {
-        if (currentItem->text(1) == host->name && currentItem->text(2) == host->portnumber)
+        if (currentItem->text(HOST_NAME_COLUMN) == host->name && currentItem->text(HOST_PORT_COLUMN) == host->portnumber)
         {
             hostConf.nameIN->setText(host->name);
             hostConf.hostname->setText(host->hostname);
@@ -822,8 +852,8 @@
                 host->hostname   = hostConf.hostname->text();
                 host->portnumber = hostConf.portnumber->text();
 
-                currentItem->setText(1, hostConf.nameIN->text());
-                currentItem->setText(2, hostConf.portnumber->text());
+                currentItem->setText(HOST_NAME_COLUMN, hostConf.nameIN->text());
+                currentItem->setText(HOST_PORT_COLUMN, hostConf.portnumber->text());
 
                 //ksw->data()->INDIHostsList.replace(i, hostItem);
 
@@ -842,8 +872,8 @@
         return;
 
     for (int i=0; i < ksw->data()->INDIHostsList.count(); i++)
-        if (ui->clientTreeWidget->currentItem()->text(1) == ksw->data()->INDIHostsList[i]->name &&
-                ui->clientTreeWidget->currentItem()->text(2) == ksw->data()->INDIHostsList[i]->portnumber)
+        if (ui->clientTreeWidget->currentItem()->text(HOST_NAME_COLUMN) == ksw->data()->INDIHostsList[i]->name &&
+                ui->clientTreeWidget->currentItem()->text(HOST_PORT_COLUMN) == ksw->data()->INDIHostsList[i]->portnumber)
         {
             if (ksw->data()->INDIHostsList[i]->isConnected)
             {
@@ -851,7 +881,7 @@
                 return;
             }
 
-            if (KMessageBox::warningContinueCancel( 0, i18n("Are you sure you want to remove the %1 client?", ui->clientTreeWidget->currentItem()->text(1)), i18n("Delete Confirmation"),KStandardGuiItem::del())!=KMessageBox::Continue)
+            if (KMessageBox::warningContinueCancel( 0, i18n("Are you sure you want to remove the %1 client?", ui->clientTreeWidget->currentItem()->text(HOST_NAME_COLUMN)), i18n("Delete Confirmation"),KStandardGuiItem::del())!=KMessageBox::Continue)
                 return;
 
             delete ksw->data()->INDIHostsList.takeAt(i);
--- trunk/KDE/kdeedu/kstars/kstars/indi/indidriver.h #1184931:1184932
@@ -89,6 +89,9 @@
     QIcon localMode;
     QIcon serverMode;
 
+public slots:
+    void makePortEditable(QTreeWidgetItem* selectedItem, int column);
+
 };
 
 class INDIDriver : public KDialog
@@ -98,6 +101,9 @@
 
 public:
 
+    enum { LOCAL_NAME_COLUMN=0, LOCAL_STATUS_COLUMN, LOCAL_MODE_COLUMN, LOCAL_VERSION_COLUMN, LOCAL_PORT_COLUMN };
+    enum { HOST_STATUS_COLUMN=0, HOST_NAME_COLUMN, HOST_PORT_COLUMN };
+
     INDIDriver(KStars *ks);
     ~INDIDriver();
 
--- trunk/KDE/kdeedu/kstars/kstars/tools/lcgenerator.cpp #1184931:1184932
@@ -124,7 +124,6 @@
     buf.append('?'+ (lcg->VisualCheck->isChecked() ? Yes : No));
     buf.append('?'+ (lcg->DiscrepantCheck->isChecked() ? Yes : No));
 
-
     KUrl url(buf);
     QString message = i18n( "Light Curve produced by the American Amateur Variable Star Observers" );
 


More information about the Kstars-devel mailing list