know bugs fixed and added search box to do a search with a contact name
[vncallhistory] / mainwindow.cc
index fad4da9..273440e 100644 (file)
@@ -21,6 +21,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 #include <QtCore/QCoreApplication>
 #include <QDebug>
 
+#include <QInputDialog>
 
 #include "listitemdetaildelegate.h"
 
@@ -61,6 +62,9 @@ MainWindow::MainWindow(QWidget *parent):
 
         m_elv1db->m_type_query = 0;
 
+        m_in_search = false;
+        m_type_query_temp = 0;
+
         connect(m_elv1db, SIGNAL(group_by_finished()), this, SLOT(elv1db_finised()));
         connect(m_elv1db, SIGNAL(detail_finished()), this, SLOT(elv1db_detail_finised()));
         connect(m_elv1db, SIGNAL(start_indicator()), this, SLOT(start_indicator()));
@@ -86,6 +90,7 @@ MainWindow::~MainWindow()
     delete this->m_contacts_widget;
     delete this->m_contact_detail;
     delete this->m_elv1db;
+    delete this->m_no_search;
 }
 
 void MainWindow::cellClicked(int row, int col){
@@ -124,7 +129,7 @@ void MainWindow::elv1db_detail_finised(){
                   (t_cache.year()!=ef->get_startdate().year()) ){
 
             QListWidgetItem *header = new QListWidgetItem();
-            header->setData(Qt::DisplayRole, ef->get_startdate().toString());
+            header->setData(Qt::DisplayRole, ef->get_startdate().toString().toUtf8());
             m_contact_detail->addItem(header);
 
             t_cache=ef->get_startdate();
@@ -250,6 +255,12 @@ void MainWindow::setup_menu(){
     connect(m_clear_log,SIGNAL(triggered()), this, SLOT(clearLog()));
     connect(m_options, SIGNAL(triggered()), this, SLOT(dlgOptions()));*/
 
+    QAction *m_search = this->menuBar()->addAction("Search");
+    connect(m_search,SIGNAL(triggered()), this, SLOT(dlgSearch()));
+
+    m_no_search = this->menuBar()->addAction("Search is Off");
+    connect(m_no_search,SIGNAL(triggered()), this, SLOT(noSearch()));
+
     QAction *m_about = this->menuBar()->addAction("About");
     QAction *m_about_qt = this->menuBar()->addAction("About Qt");
 
@@ -258,15 +269,46 @@ void MainWindow::setup_menu(){
 
 }
 
+void MainWindow::noSearch(){
+    if (m_in_search){
+        m_contacts_widget->setEnabled(false);
+        m_no_search->setText("Search is Off");
+        m_elv1db->m_type_query = m_type_query_temp;
+        m_in_search = false;
+        m_elv1db->start();
+    }
+}
+
+void MainWindow::dlgSearch(){
+    bool ok;
+    QString text = QInputDialog::getText(this, tr("Search"),
+                                         tr("Give me a contact name to do a search :"), QLineEdit::Normal,
+                                         *m_elv1db->m_search_val, &ok);
+    if (ok && !text.isEmpty() && !text.trimmed().isEmpty()){
+        m_no_search->setText("Search is On");
+        m_in_search = true;
+        this->doSearch(text);
+    }
+}
+
+void MainWindow::doSearch(QString val){
+    m_contacts_widget->setEnabled(false);
+    *m_elv1db->m_search_val = val;
+    m_elv1db->m_type_query = 2;
+    m_elv1db->start();
+}
+
 void MainWindow::select_all_call(){ //ring/tel/ring, spirit/skype, gabble/jabber
     m_contacts_widget->setEnabled(false);
     m_elv1db->m_all_call = true;
+    m_type_query_temp = 0;
     m_elv1db->start();
 }
 
 void MainWindow::select_gsm_calls(){ //ring/tel/ring
     m_contacts_widget->setEnabled(false);
     m_elv1db->m_all_call = false;
+    m_type_query_temp = 0;
     m_elv1db->start();
 }
 
@@ -305,7 +347,7 @@ void MainWindow::dlgAbout(){
     m_about.setWindowTitle("About");
     m_about.setText(
                 "<font size=4>VN Call History</font><br>"
-                "<font size=3>Version : 0.0.1 (09/28/2011)</font><br>"
+                "<font size=3>Version : 0.0.2 (09/29/2011)</font><br>"
                 "Author : Cuong Le <a href=\"mailto:metacuong@gmail.com\">metacuong@gmail.com</a><br>"
                 "<font size=2>"
                 "Homepage : <a href=\"http://vncallhistory.garage.maemo.org/\">http://vncallhistory.garage.maemo.org/</a><br>"