1 #include "mainwindow.h"
4 #include "contactmodifyer.h"
7 * Constructs a MainWindow which is a child of 'parent', with the
8 * name 'name' and widget flags set to 'f'
10 MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl )
11 : CMainWindowBase( parent, name, fl )
16 * Destroys the object and frees any allocated resources
18 MainWindow::~MainWindow()
20 // no need to delete child widgets, Qt does it all for us
26 void MainWindow::slotSave()
28 if (filename.isNull())
30 filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)");
31 if (filename.isNull())
39 if ( !f.open( IO_WriteOnly ) )
44 CContact* contact = CContact::getFirst();
46 while ( contact != '\0')
48 t << contact->firstname() << "\n";
49 t << contact->lastname() << "\n";
50 t << contact->adress() << "\n";
51 t << contact->phoneNumber() << "\n";
52 contact=contact->getNext();
59 void MainWindow::slotAdd()
62 if(add.exec() == QDialog::Accepted)
68 void MainWindow::slotDel()
70 QListViewItem* lvi = ContactView->selectedItem();
77 int num = lvi->text(0).toInt();
79 if (num < 1 || num > CContact::getNum())
82 CContact* contact = CContact::getFirst();
84 for (int i = 1; i < num; i++, contact = contact->getNext())
86 if (contact->getNext() == '\0')
94 //qWarning( "MainWindow::slotDel() not yet implemented!" );
99 void MainWindow::slotLoad()
101 filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this);
104 if ( !f.open( IO_ReadOnly ) )
107 while (CContact::getNum() != 0)
109 delete CContact::getFirst();
116 QString fname = t.readLine();
117 QString lname = t.readLine();
118 QString adr = t.readLine();
119 QString pn = t.readLine();
120 if (fname == "" && lname == "" && lname == "" && pn == "")
122 (void) new CContact(fname, lname, adr, pn);
129 void MainWindow::slotSearch()
131 qWarning( "MainWindow::slotSearch() not yet implemented!" );
134 void MainWindow::slotModify(QListViewItem* lvi)
141 int num = lvi->text(0).toInt();
143 if (num < 1 || num > CContact::getNum())
146 CContact* contact = CContact::getFirst();
148 for (int i = 1; i < num; i++, contact = contact->getNext())
150 if (contact->getNext() == '\0')
155 ContactModifier modify(contact);
156 if(modify.exec() == QDialog::Accepted)
160 void MainWindow::slotModify()
162 QListViewItem* lvi = ContactView->selectedItem();
169 int num = lvi->text(0).toInt();
171 if (num < 1 || num > CContact::getNum())
174 CContact* contact = CContact::getFirst();
176 for (int i = 1; i < num; i++, contact = contact->getNext())
178 if (contact->getNext() == '\0')
183 ContactModifier modify(contact);
184 if(modify.exec() == QDialog::Accepted)
188 * This funtion puts all contacts in the listview
190 void MainWindow::updateView()
193 ContactView->clear();
195 CContact* contact = CContact::getFirst();
200 while (contact != '\0')
202 sprintf(s,"%i",i);//.arg(i);
203 (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
204 contact = contact->getNext();