fixed an error in storing macs with zeroes.
[woller] / woller.cpp
index 58d1e85..d78162c 100644 (file)
 // along with Woller.  If not, see <http://www.gnu.org/licenses/>.
 
 
+#ifdef Q_WS_MAEMO_5
+  #include <QtMaemo5>
+#endif
 #include "woller.h"
 
+MainWindow::MainWindow()
+{
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+    woller = new Woller(this);
+    this->setCentralWidget(woller);
+}
+
+MainWindow::~MainWindow()
+{
+    delete woller;
+}
+
 
 Woller::Woller(QWidget *parent)
         : QWidget(parent)
@@ -47,6 +64,11 @@ Woller::Woller(QWidget *parent)
     vlayout->addLayout(hlayout);
     this->setLayout(vlayout);
     this->setWindowTitle(tr("Woller-program"));
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+#else
+    this->setWindowModality(Qt::ApplicationModal);
+#endif
 
     //populate CB
     load_config();
@@ -110,8 +132,7 @@ void Woller::targets_act(int i)
     {
         // build the config widget
         qDebug() << "building the config" << endl;
-        config_win = new ConfigWidget(0, hosts_list);
-        config_win->setWindowModality(Qt::ApplicationModal);
+        config_win = new ConfigWidget(this, hosts_list);
         connect(config_win, SIGNAL(hosts_changed()), this, SLOT(hosts_changed()));
         config_win->show();
     }
@@ -187,6 +208,12 @@ ConfigWidget::ConfigWidget(QWidget *parent, QList<host_s> *hosts)
 
     //add buttons and the list
     this->setWindowTitle(tr("Woller Config"));
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+#else
+    this->setWindowModality(Qt::ApplicationModal);
+#endif
+    this->setWindowFlags(this->windowFlags() | Qt::Window);
     add_host = new QPushButton(tr("&Add Host"), this);
     edit_host = new QPushButton(tr("&Edit Host"), this);
     del_host = new QPushButton(tr("&Delete Host"), this);
@@ -242,9 +269,8 @@ void ConfigWidget::add_sig()
     host_tmp.hostname.clear();
     host_tmp.mac.clear();
     host_tmp.ip.clear();
-    host_widget = new HostWidget(0, &host_tmp);
+    host_widget = new HostWidget(this, &host_tmp);
 
-    host_widget->setWindowModality(Qt::ApplicationModal);
     connect(host_widget, SIGNAL(change_host()), this, SLOT(host_added()));
     host_widget->show();
     qDebug() << "conf add - exit" << endl;
@@ -257,10 +283,9 @@ void ConfigWidget::edit_sig()
     host_tmp.hostname = hosts_list->at(list->currentIndex().row()).hostname;
     host_tmp.mac = hosts_list->at(list->currentIndex().row()).mac;
     host_tmp.ip = hosts_list->at(list->currentIndex().row()).ip;
-    host_widget = new HostWidget(0, &host_tmp);
+    host_widget = new HostWidget(this, &host_tmp);
     connect(host_widget, SIGNAL(change_host()), this, SLOT(host_edited()));
 
-    host_widget->setWindowModality(Qt::ApplicationModal);
     //hostWidget->hostname->setPlaceholderText("my_host_name");
     //hostWidget->hostname->setText("edit1");
     //hostWidget->mac->setPlaceholderText("001133aabbcc");
@@ -340,7 +365,13 @@ HostWidget::HostWidget(QWidget *parent, host_s *host)
 
     qDebug() << "host widget" << endl;
     new_host = host;
-    this->setWindowTitle("Add new WOL target host");
+    this->setWindowTitle(tr("WOL target details"));
+#ifdef Q_WS_MAEMO_5
+    this->setAttribute(Qt::WA_Maemo5StackedWindow);
+#else
+    this->setWindowModality(Qt::ApplicationModal);
+#endif
+    this->setWindowFlags(this->windowFlags() | Qt::Window);
     vlayout = new QVBoxLayout(this);
 
     host_row = new QHBoxLayout;
@@ -358,7 +389,7 @@ HostWidget::HostWidget(QWidget *parent, host_s *host)
             tr("HW address of target, e.g. 00:01:02:AA:BB:CC. "
                "Hint, in Linux/Unix: \"ifconfig\","
                "in Windows \"ipconfig /all\""));
-    mac->setInputMask("HH:HH:HH:HH:HH:HH;0");
+    mac->setInputMask("HH:HH:HH:HH:HH:HH;_");
     mac_row->addWidget(mac_lbl);
     mac_row->addWidget(mac);
     vlayout->addLayout(mac_row);
@@ -411,11 +442,13 @@ void HostWidget::ok_sig()
         msgBox.exec();
         return;
     }
-    new_host->mac= this->mac->text();
-    if (new_host->mac.isEmpty())
+
+    new_host->mac = this->mac->text();
+    if (new_host->mac.length() != MAX_MAC_STR_LEN)
     {
         QMessageBox msgBox;
-        msgBox.setText("You must set mac!");
+        msgBox.setText("You must set mac to full 12 digits!\n" \
+                       "E.g. 00:11:22:33:44:55:66");
         msgBox.exec();
         return;
     }
@@ -431,7 +464,6 @@ void HostWidget::ok_sig()
 HostWidget::~HostWidget()
 {
     qDebug() << "host ~widget" << endl;
-    delete vlayout;
     delete host_row;
     delete host_lbl;
     delete hostname;
@@ -444,7 +476,7 @@ HostWidget::~HostWidget()
     delete button_row;
     delete cancel;
     delete ok;
-    //delete new_host;
+    delete vlayout;
 }