know bugs fixed and added search box to do a search with a contact name
[vncallhistory] / elv1db.cc
index 9f5f4da..d76fcb5 100644 (file)
--- a/elv1db.cc
+++ b/elv1db.cc
@@ -28,6 +28,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>
 elv1db::elv1db(QObject *parent):
     QThread(parent),
     m_type_query(0),
+    m_search_val(new QString("")),
     m_db(QSqlDatabase::addDatabase("QSQLITE"))
 {
     m_db.setDatabaseName("/home/user/.rtcom-eventlogger/el-v1.db");
@@ -37,6 +38,7 @@ elv1db::elv1db(QObject *parent):
 elv1db::~elv1db(){
     if (m_db.isOpen())
         m_db.close();
+    delete this->m_search_val;
 }
 
 PhoneType elv1db::phonetype(QString metastr){
@@ -52,26 +54,36 @@ PhoneType elv1db::phonetype(QString metastr){
 }
 
 QString elv1db::calltype(){
-    return this->m_call_type==ALL_CALL?"and (event_type_id = 1 or event_type_id = 3)":
+    return this->m_call_type==ALL_CALL?"and (event_type_id = 1 or event_type_id = 2)":
                                                       this->m_call_type==INCOMING?"and event_type_id = 1  and outgoing = 0":
-                                                      this->m_call_type==OUTGOING?"and event_type_id = 1  and outgoing = 1":"and event_type_id = 3";
+                                                      this->m_call_type==OUTGOING?"and event_type_id = 1  and outgoing = 1":"and event_type_id = 2";
 }
 
 void elv1db::run(){
-    if (this->m_type_query == 0)
+    if (this->m_type_query == 0 || this->m_type_query == 2)
         emit start_indicator();
     else
         emit detail_start_indicator();
 
     sleep(1);
 
-    if (this->m_type_query == 0){
+    if (this->m_type_query == 0){ //all
         QString m_group_by_call(H_TOTAL_GROUP_BY);
         setQuery(m_group_by_call
                  .arg(this->m_all_call?"":"and E.local_uid='ring/tel/ring'")
                  .arg(calltype()));
     }
-    else{
+    else if (this->m_type_query == 2 ){ //doSearch
+        QString m_group_by_and_search_call(H_TOTAL_GROUP_BY_AND_SEARCH);
+        QString m_search_val_convert("and remote_name like '%%1%'");
+        m_search_val_convert = m_search_val_convert.arg(*this->m_search_val);
+
+        setQuery(m_group_by_and_search_call
+                 .arg(this->m_all_call?"":"and E.local_uid='ring/tel/ring'")
+                 .arg(calltype())
+                 .arg(m_search_val_convert));
+    }
+    else { // for contact details
         QString m_filter(" and remote_name = '%1' %2 ");
         m_filter = m_filter.arg(m_contact_name).arg(calltype());
         QString m_default_search = QString(H_DEFAULT_SEARCH).arg(m_filter).arg(100);
@@ -81,7 +93,7 @@ void elv1db::run(){
     QSqlQuery *query = new QSqlQuery(this->m_query);
     QSqlRecord record = query->record();
     if(record.count() > 0){
-        if (this->m_type_query == 0){
+        if (this->m_type_query == 0 || this->m_type_query == 2){
             this->m_records.clear();
               while (query->next()) {
                   elv1rec *ef=new elv1rec();
@@ -89,7 +101,8 @@ void elv1db::run(){
                   ef->set_total_call(query->value(1).value<QString>());
                   this->m_records << ef;
               }
-        }else{
+        }
+        else{
 
             this->m_detail_records.clear();
 
@@ -98,7 +111,7 @@ void elv1db::run(){
 
                 int calltype =  query->value(0).value< int >();
 
-                if (calltype == 1 || calltype == 3){
+                if (calltype == 1 || calltype == 2){
                     ef->set_phonenumber(query->value(5).value<QString>());
                     ef->set_starttime(query->value(1).value<uint>());
                     ef->set_endtime(query->value(2).value<uint>());
@@ -124,7 +137,7 @@ void elv1db::run(){
 
     delete query;
 
-    if (this->m_type_query == 0)
+    if (this->m_type_query == 0 || this->m_type_query == 2)
         emit group_by_finished();
     else
         emit detail_finished();