1 #include "mainwindow.h"
4 #include "contactmodifyer.h"
5 #include "searchresult.h"
8 * Constructs a MainWindow which is a child of 'parent', with the
9 * name 'name' and widget flags set to 'f'
11 MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
12 : CMainWindowBase( parent, name, fl )
17 * Destroys the object and frees any allocated resources
19 MainWindow::~MainWindow()
21 // no need to delete child widgets, Qt does it all for us
27 void MainWindow::slotSave()
29 if (filename.isNull())
31 filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)");
32 if (filename.isNull())
40 if ( !f.open( IO_WriteOnly ) )
45 CContact* contact = CContact::getFirst();
47 while ( contact != '\0')
49 t << contact->firstname() << "\n";
50 t << contact->lastname() << "\n";
51 t << contact->adress() << "\n";
52 t << contact->phoneNumber() << "\n";
53 contact=contact->getNext();
60 void MainWindow::slotAdd()
63 if(add.exec() == QDialog::Accepted)
69 void MainWindow::slotDel()
71 QListViewItem* lvi = ContactView->selectedItem();
78 int num = lvi->text(0).toInt();
80 if (num < 1 || num > CContact::getNum())
83 CContact* contact = CContact::getFirst();
85 for (int i = 1; i < num; i++, contact = contact->getNext())
87 if (contact->getNext() == '\0')
95 //qWarning( "MainWindow::slotDel() not yet implemented!" );
100 void MainWindow::slotLoad()
102 filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this);
105 if ( !f.open( IO_ReadOnly ) )
108 while (CContact::getNum() != 0)
110 delete CContact::getFirst();
117 QString fname = t.readLine();
118 QString lname = t.readLine();
119 QString adr = t.readLine();
120 QString pn = t.readLine();
121 if (fname == "" && lname == "" && lname == "" && pn == "")
123 (void) new CContact(fname, lname, adr, pn);
130 void MainWindow::slotSearch()
132 if (SearchLine->text().isNull())
135 SearchResult search(SearchLine->text(), SearchCombo->currentItem() + 1);
140 void MainWindow::slotModify(QListViewItem* lvi)
147 int num = lvi->text(0).toInt();
149 if (num < 1 || num > CContact::getNum())
152 CContact* contact = CContact::getFirst();
154 for (int i = 1; i < num; i++, contact = contact->getNext())
156 if (contact->getNext() == '\0')
161 ContactModifier modify(contact);
162 if(modify.exec() == QDialog::Accepted)
166 void MainWindow::slotModify()
168 QListViewItem* lvi = ContactView->selectedItem();
175 int num = lvi->text(0).toInt();
177 if (num < 1 || num > CContact::getNum())
180 CContact* contact = CContact::getFirst();
182 for (int i = 1; i < num; i++, contact = contact->getNext())
184 if (contact->getNext() == '\0')
189 ContactModifier modify(contact);
190 if(modify.exec() == QDialog::Accepted)
194 * This funtion puts all contacts in the listview
196 void MainWindow::updateView()
199 ContactView->clear();
201 CContact* contact = CContact::getFirst();
206 while (contact != '\0')
208 sprintf(s,"%i",i);//.arg(i);
209 (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
210 contact = contact->getNext();