]> ruin.nu Git - adress.git/commitdiff
Added the files needed for searching.. master origin a
authorMichael Andreen <harv@ruin.nu>
Mon, 11 Dec 2000 05:53:36 +0000 (05:53 +0000)
committerMichael Andreen <harv@ruin.nu>
Mon, 11 Dec 2000 05:53:36 +0000 (05:53 +0000)
searchresult.cpp [new file with mode: 0644]
searchresult.h [new file with mode: 0644]

diff --git a/searchresult.cpp b/searchresult.cpp
new file mode 100644 (file)
index 0000000..03bbb42
--- /dev/null
@@ -0,0 +1,113 @@
+#include "searchresult.h"
+#include <stdio.h>
+
+#include <qlistview.h>
+
+//local includes
+#include "contact.h"
+#include "contactmodifyer.h"
+
+/* 
+ *  Constructs a SearchResult which is a child of 'parent', with the 
+ *  name 'name' and widget flags set to 'f' 
+ *
+ *  The dialog will by default be modeless, unless you set 'modal' to
+ *  TRUE to construct a modal dialog.
+ */
+SearchResult::SearchResult(QString searchword, int cat, QWidget* parent,  const char* name, bool modal, WFlags fl )
+    : SearchResultBase( parent, name, modal, fl )
+{
+       m_searchword = searchword;
+       m_cat = cat;
+       Find();
+}
+
+/*  
+ *  Destroys the object and frees any allocated resources
+ */
+SearchResult::~SearchResult()
+{
+    // no need to delete child widgets, Qt does it all for us
+}
+
+/* 
+ * public slot
+ */
+void SearchResult::slotDel()
+{
+       QListViewItem* lvi = ContactView->selectedItem();
+
+       if (lvi == '\0')
+       {
+               return;
+       }
+
+       int num = lvi->text(0).toInt();
+
+       if (num < 1 || num > CContact::getNum())
+               return;
+
+       CContact* contact = CContact::getFirst();
+
+       for (int i = 1; i < num; i++, contact = contact->getNext())
+       {
+               if (contact->getNext() == '\0')
+         {
+                 return;
+               }
+       }
+
+       delete contact;
+       Find();
+}
+/* 
+ * public slot
+ */
+void SearchResult::slotModify()
+{
+       QListViewItem* lvi = ContactView->selectedItem();
+        
+       if (lvi == '\0')
+       {
+               return;
+       }
+                 
+       int num = lvi->text(0).toInt();
+                        
+       if (num < 1 || num > CContact::getNum())
+               return;
+                                
+       CContact* contact = CContact::getFirst();
+                                         
+       for (int i = 1; i < num; i++, contact = contact->getNext())
+       {
+               if (contact->getNext() == '\0')
+         {
+                 return;
+               }
+       }
+       ContactModifier modify(contact);
+       if(modify.exec() == QDialog::Accepted)
+               Find();
+}
+
+//Protected functions
+void SearchResult::Find()
+{
+       ContactView->clear();
+       CContact* contact = CContact::getFirst();
+
+       int i = 1;
+       char s[100];
+
+       while (contact != '\0')
+       {
+               if (contact->search(m_cat, m_searchword))
+               {
+                       sprintf(s,"%i",i);//.arg(i);
+                       (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
+               }
+               contact = contact->getNext();
+               i++;
+       }
+}
diff --git a/searchresult.h b/searchresult.h
new file mode 100644 (file)
index 0000000..128d4dc
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef SEARCHRESULT_H
+#define SEARCHRESULT_H
+#include "ui/searchresultbase.h"
+
+//QT includes
+#include <qstring.h>
+
+class SearchResult : public SearchResultBase
+{ 
+    Q_OBJECT
+
+public:
+    SearchResult(QString searchword, int cat, QWidget* parent = 0, const char* name = 0, bool modal = true, WFlags fl = 0 );
+    ~SearchResult();
+
+public slots:
+    void slotDel();
+    void slotModify();
+
+protected: //Attributes
+               QString m_searchword;
+               int                     m_cat;
+
+protected: //FUnktions
+               void Find();
+};
+
+#endif // SEARCHRESULT_H