]> ruin.nu Git - adress.git/blob - searchresult.cpp
Added the files needed for searching..
[adress.git] / searchresult.cpp
1 #include "searchresult.h"
2 #include <stdio.h>
3
4 #include <qlistview.h>
5
6 //local includes
7 #include "contact.h"
8 #include "contactmodifyer.h"
9
10 /* 
11  *  Constructs a SearchResult which is a child of 'parent', with the 
12  *  name 'name' and widget flags set to 'f' 
13  *
14  *  The dialog will by default be modeless, unless you set 'modal' to
15  *  TRUE to construct a modal dialog.
16  */
17 SearchResult::SearchResult(QString searchword, int cat, QWidget* parent,  const char* name, bool modal, WFlags fl )
18     : SearchResultBase( parent, name, modal, fl )
19 {
20         m_searchword = searchword;
21         m_cat = cat;
22         Find();
23 }
24
25 /*  
26  *  Destroys the object and frees any allocated resources
27  */
28 SearchResult::~SearchResult()
29 {
30     // no need to delete child widgets, Qt does it all for us
31 }
32
33 /* 
34  * public slot
35  */
36 void SearchResult::slotDel()
37 {
38         QListViewItem* lvi = ContactView->selectedItem();
39
40         if (lvi == '\0')
41         {
42                 return;
43         }
44
45         int num = lvi->text(0).toInt();
46
47         if (num < 1 || num > CContact::getNum())
48                 return;
49
50         CContact* contact = CContact::getFirst();
51
52         for (int i = 1; i < num; i++, contact = contact->getNext())
53         {
54                 if (contact->getNext() == '\0')
55           {
56                   return;
57                 }
58         }
59
60         delete contact;
61         Find();
62 }
63 /* 
64  * public slot
65  */
66 void SearchResult::slotModify()
67 {
68         QListViewItem* lvi = ContactView->selectedItem();
69          
70         if (lvi == '\0')
71         {
72                 return;
73         }
74                   
75         int num = lvi->text(0).toInt();
76                          
77         if (num < 1 || num > CContact::getNum())
78                 return;
79                                  
80         CContact* contact = CContact::getFirst();
81                                           
82         for (int i = 1; i < num; i++, contact = contact->getNext())
83         {
84                 if (contact->getNext() == '\0')
85           {
86                   return;
87                 }
88         }
89         ContactModifier modify(contact);
90         if(modify.exec() == QDialog::Accepted)
91                 Find();
92 }
93
94 //Protected functions
95 void SearchResult::Find()
96 {
97         ContactView->clear();
98         CContact* contact = CContact::getFirst();
99
100         int i = 1;
101         char s[100];
102
103         while (contact != '\0')
104         {
105                 if (contact->search(m_cat, m_searchword))
106                 {
107                         sprintf(s,"%i",i);//.arg(i);
108                         (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
109                 }
110                 contact = contact->getNext();
111                 i++;
112         }
113 }