Updated packaging files in debian folder.
[ptas] / zouba / src / ui.cpp
index 8e269c1..da74a1a 100644 (file)
@@ -1,7 +1,7 @@
 #include "ui.h"
 
-#include "locations.h"
-#include "ytv.h"
+#include "logic/locations.h"
+#include "logic/ytv.h"
 
 #include <QMainWindow>
 #include <QRadioButton>
 #include <QSizePolicy>
 #include <QInputDialog>
 #include <QDebug>
-
-Ui::Ui() :
-  m_centralWidget(0),
-  m_destinationButtons(0),
-  m_routeStack(0),
-  m_usingFakeGps( false ),
-  m_fakeLocationLabel( "work" )
+#include <QMenu>
+#include <QPushButton>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5ValueButton>
+#include <QMaemo5ListPickSelector>
+#endif
+#include <QStandardItemModel>
+
+UiClass::UiClass() :
+        m_centralWidget(NULL),
+        m_routeStack(NULL),
+        m_locDisp(NULL)
 {
 }
 
-Ui::~Ui()
+UiClass::~UiClass()
 {
+    delete m_locDisp;
 }
 
-void Ui::setupUi( QMainWindow *mainWindow )
+void UiClass::setupUi( QMainWindow *mainWindow )
 {
-  m_mainWindow = mainWindow;
-  m_mainWindow->resize(800,480);
-
-  m_menu = mainWindow->menuBar()->addMenu("Settings");
-
-  QAction *setHomeAddressAction = new QAction("Set home address", this);
-  QAction *setWorkAddressAction = new QAction("Set work address", this);
-  m_toggleFakeGpsAction  = new QAction("Use fake GPS", this);
-  m_menu->addAction(setHomeAddressAction);
-  m_menu->addAction(setWorkAddressAction);
-  m_menu->addAction(m_toggleFakeGpsAction);
-
-  connect(
-      setHomeAddressAction, SIGNAL(triggered()),
-      this, SLOT(setHomeAddress())
-      );
-  connect(
-      setWorkAddressAction, SIGNAL(triggered()),
-      this, SLOT(setWorkAddress())
-      );
-  connect(
-      m_toggleFakeGpsAction, SIGNAL(triggered()),
-      this, SLOT(toggleFakeGps())
-      );
-
-  m_centralWidget = new QWidget( m_mainWindow );
-  m_mainWindow->setCentralWidget( m_centralWidget);
-
-  QRadioButton *homeButton = new QRadioButton();
-  homeButton->setObjectName( QString::fromUtf8("homeButton") );
-  homeButton->setText( "GPS->HOME" );
-  homeButton->setEnabled(false);
-
-  QRadioButton *workButton = new QRadioButton();
-  workButton->setObjectName( QString::fromUtf8("workButton") );
-  workButton->setText( "GPS->WORK" );
-  workButton->setEnabled(false);
-
-  m_destinationButtons = new QButtonGroup();
-  m_destinationButtons->addButton( homeButton, HomeButtonId );
-  m_destinationButtons->addButton( workButton, WorkButtonId );
-  m_destinationButtons->setExclusive( true );
-
-  m_routeButtons = new QButtonGroup();
-  m_routeButtons->setExclusive( true );
-  m_routeStack = new QVBoxLayout();
-  for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
-    QRadioButton *button = new QRadioButton();
-    button->setObjectName( "routeButton"+i );
-    button->setEnabled( false );
-
-    m_routeStack->addWidget( button, i );
-    m_routeButtons->addButton( button, i );
-  }
-  m_routeStack->addStretch();
-
-  QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
-  m_routeDetailTable = new QTableWidget();
-  m_routeDetailTable->setColumnCount( headers.count() );
-  m_routeDetailTable->setHorizontalHeaderLabels( headers );
-  m_routeDetailTable->resizeColumnsToContents();
-  m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
-
-  QHBoxLayout *topLayout = new QHBoxLayout();
-  topLayout->addLayout( m_routeStack );
-  topLayout->addWidget( m_routeDetailTable );
-
-  m_buttonLayout = new QGridLayout();
-  m_buttonLayout->addWidget( homeButton, 0, 0 );
-  m_buttonLayout->addWidget( workButton, 0, 1 );
-
-  m_mainLayout = new QVBoxLayout();
-  m_mainLayout->addLayout( topLayout );
-  m_mainLayout->addLayout( m_buttonLayout );
-
-  m_centralWidget->setLayout( m_mainLayout );
+    m_mainWindow = mainWindow;
+#ifdef Q_WS_MAEMO_5
+    m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
+#endif
+    //m_mainWindow->resize(800,480);
+
+    m_locDisp = new LocationsDisplayWindow(mainWindow);
+
+    m_menu = mainWindow->menuBar();
+
+    /*QAction *setHomeAddressAction = new QAction("Set home address", this);
+    QAction *setWorkAddressAction = new QAction("Set work address", this);*/
+    QAction *modifyLocationsAction = new QAction("Modify locations", this);
+    m_UseGpsAction  = new QAction("Use GPS", this);
+    m_UseGpsAction->setCheckable(true);
+    m_UseGpsAction->setChecked(true);
+    connect(this->m_UseGpsAction, SIGNAL(toggled(bool)), this, SLOT(setLocations()));
+    /*m_menu->addAction(setHomeAddressAction);
+    m_menu->addAction(setWorkAddressAction);*/
+    m_menu->addAction(m_UseGpsAction);
+    m_menu->addAction(modifyLocationsAction);
+
+    /*connect(
+            setHomeAddressAction, SIGNAL(triggered()),
+            this, SLOT(setHomeAddress())
+            );
+    connect(
+            setWorkAddressAction, SIGNAL(triggered()),
+            this, SLOT(setWorkAddress())
+            );*/
+
+    connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
+
+    Locations* locations = Locations::GetInstance();
+    connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
+
+    m_centralWidget = new QWidget( m_mainWindow );
+    m_mainWindow->setCentralWidget( m_centralWidget);
+
+    m_locationsModel = new QStandardItemModel(0,1);
+    this->setLocations();
+
+#ifdef Q_WS_MAEMO_5
+    m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
+    m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
+    fromSelector->setModel(m_locationsModel);
+    m_fromButton->setPickSelector(fromSelector);
+
+    m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
+    m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
+    toSelector->setModel(m_locationsModel);
+    m_toButton->setPickSelector(toSelector);
+#endif
+
+    m_routeButton = new QPushButton("Route");
+
+    m_routeButtons = new QButtonGroup();
+    m_routeButtons->setExclusive( true );
+    m_routeStack = new QVBoxLayout();
+    for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
+        QRadioButton *button = new QRadioButton();
+        button->setObjectName( "routeButton"+i );
+        button->setEnabled( false );
+
+        m_routeStack->addWidget( button, i );
+        m_routeButtons->addButton( button, i );
+    }
+    m_routeStack->addStretch();
+
+    QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
+    m_routeDetailTable = new QTableWidget();
+    m_routeDetailTable->setColumnCount( headers.count() );
+    m_routeDetailTable->setHorizontalHeaderLabels( headers );
+    m_routeDetailTable->resizeColumnsToContents();
+    m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
+
+    QHBoxLayout *topLayout = new QHBoxLayout();
+    topLayout->addLayout( m_routeStack );
+    topLayout->addWidget( m_routeDetailTable );
+
+    m_buttonLayout = new QGridLayout();
+#ifdef Q_WS_MAEMO_5
+    m_buttonLayout->addWidget(m_fromButton, 0, 0);
+    m_buttonLayout->addWidget(m_toButton, 0, 1);
+#endif
+    m_buttonLayout->addWidget(m_routeButton, 0, 2);
+
+    m_mainLayout = new QVBoxLayout();
+    m_mainLayout->addLayout( topLayout );
+    m_mainLayout->addLayout( m_buttonLayout );
+
+    m_centralWidget->setLayout( m_mainLayout );
 }
 
-void Ui::setHomeAddress()
+void UiClass::setLocations()
 {
-  setAddress( "home" );
-}
+    qDebug() << "Setting locations for main menu selectors.";
+    Locations *locations = Locations::GetInstance();
+
+    m_locationsModel->clear();
+    QStandardItem *item;
+    if (this->m_UseGpsAction->isChecked())
+    {
+        item = new QStandardItem(QString("GPS"));
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 
-void Ui::setWorkAddress()
-{
-  setAddress( "work" );
+    for (int index = 1; index <= locations->size(); ++index)
+    {
+        item = new QStandardItem(locations->getLocation(index)->label());
+        item->setTextAlignment(Qt::AlignCenter);
+        item->setEditable(false);
+        m_locationsModel->appendRow(item);
+    }
 }
 
-void Ui::toggleFakeGps()
+void UiClass::setHomeAddress()
 {
-  m_usingFakeGps = !m_usingFakeGps;
-
-  if ( m_usingFakeGps ) {
-    useFakeGps();
-  } else {
-    useLiveGps();
-  }
+    setAddress( "home" );
 }
 
-void Ui::useFakeGps()
+void UiClass::setWorkAddress()
 {
-  emit fakeGpsPressed( m_fakeLocationLabel );
-  m_toggleFakeGpsAction->setText( "Use Live GPS" );
+    setAddress( "work" );
 }
 
-void Ui::useLiveGps()
+void UiClass::setAddress( const QString &label )
 {
-  emit liveGpsPressed();
-  m_toggleFakeGpsAction->setText( "Use Fake GPS" );
+    /*Locations locations;
+    Location *location=locations.location( label );
+
+    bool ok;
+    QString address = QInputDialog::getText(
+            m_centralWidget,
+            tr("Enter address for \""+QString(label).toLatin1()+"\""),
+            tr("Address"),
+            QLineEdit::Normal,
+            location->address(),
+            &ok
+            );
+
+    if ( ok ) {
+        qDebug() << "new address" << address;
+        Locations locations;
+        Location  *location  = locations.location( label );
+        qDebug() << "location" << location;
+        if ( location ) {
+            //location->resolveAddress( address );
+        }
+    }*/
 }
 
-void Ui::setAddress( const QString &label )
+/*void Ui::modifyLocations()
 {
-  Locations *locations=Locations::instance();
-  Location *location=locations->location( label );
-
-  bool ok;
-  QString address = QInputDialog::getText(
-     m_centralWidget,
-     tr("Enter address for \""+QString(label).toLatin1()+"\""),
-     tr("Address"),
-     QLineEdit::Normal,
-     location->address(),
-     &ok
-     );
-
-  if ( ok ) {
-    qDebug() << "new address" << address;
-    Locations *locations = Locations::instance();
-    Location  *location  = locations->location( label );
-    qDebug() << "location" << location;
-    if ( location ) {
-      location->resolveAddress( address );
-    }
-  }
-}
+    LocationsDisplay
+}*/
 
-void Ui::setBusy( bool busy )
+void UiClass::setBusy( bool busy )
 {
-  m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#ifdef Q_WS_MAEMO_5
+    m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
+#endif
 }