]> ruin.nu Git - adress.git/blob - mainwindow.cpp
ce83c8cae5d1f6b7baa8638b04c60dfe53cb3476
[adress.git] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include <iostream>
3
4 /* BRÖÖL
5  *  Constructs a MainWindow which is a child of 'parent', with the 
6  *  name 'name' and widget flags set to 'f' 
7  */
8 MainWindow::MainWindow( QWidget* parent,  const char* name, WFlags fl )
9     : CMainWindowBase( parent, name, fl )
10 {
11 }
12
13 /*  
14  *  Destroys the object and frees any allocated resources
15  */
16 MainWindow::~MainWindow()
17 {
18     // no need to delete child widgets, Qt does it all for us
19 }
20
21 /* 
22  * public slot
23  */
24 void MainWindow::slotSave()
25 {
26         if (filename.isNull())
27         {
28                 filename = QFileDialog::getSaveFileName( 0, "Adresslista (*.adr)");
29                 if (filename.isNull())
30                 {
31                         return;
32                 }
33         }                     
34
35         QFile f(filename);
36
37         if ( !f.open( IO_WriteOnly ) )
38                     return;
39               
40         QTextStream t(&f);
41         QString s;
42         CContact* contact = CContact::getFirst();
43
44         while ( contact != '\0')
45         {
46                 t << contact->firstname() << "\n";
47                 t << contact->lastname() << "\n";
48                 t << contact->adress() << "\n";
49                 t << contact->phoneNumber() << "\n";
50                 contact=contact->getNext();
51         }
52         f.close();
53 }
54 /* 
55  * public slot
56  */
57 void MainWindow::slotAdd()
58 {
59     qWarning( "MainWindow::slotAdd() not yet implemented!" ); 
60 }
61 /* 
62  * public slot
63  */
64 void MainWindow::slotDel()
65 {
66     qWarning( "MainWindow::slotDel() not yet implemented!" ); 
67 }
68 /* 
69  * public slot
70  */
71 void MainWindow::slotLoad()
72 {
73         filename = QFileDialog::getOpenFileName(0, "Adressfiler (*.adr)", this); 
74
75         QFile f(filename);
76         if ( !f.open( IO_ReadOnly ) )
77                 return;
78                         
79         while (CContact::getNum() != 0)
80         {
81                 delete CContact::getFirst();
82         }
83         
84         QTextStream t(&f);
85
86         while (!t.eof())
87         {
88                 QString fname = t.readLine();
89                 QString lname = t.readLine();
90                 QString adr             = t.readLine();
91                 QString pn              = t.readLine();
92     if (fname == "" && lname == "" && lname == "" && pn == "")
93                               continue;
94                 (void) new CContact(fname, lname, adr, pn);
95         }
96         updateView();
97 }
98 /* 
99  * public slot
100  */
101 void MainWindow::slotSearch()
102 {
103     qWarning( "MainWindow::slotSearch() not yet implemented!" ); 
104 }
105
106 void MainWindow::slotModify(QListViewItem* lvi)
107 {
108     qWarning( "MainWindow::slotModif(QListViewItem*) not yet implemented!" ); 
109 }
110 /*
111  * This funtion puts all contacts in the listview
112  */
113 void MainWindow::updateView()
114 {
115         
116         ContactView->clear();
117
118         CContact* contact = CContact::getFirst();
119
120         int i = 1;
121         char s[100];
122
123         while (contact != '\0')
124         {
125                 sprintf(s,"%i",i);//.arg(i);
126                 (void) new QListViewItem(ContactView, s, contact->lastname(), contact->firstname(), contact->adress(), contact->phoneNumber());
127                 contact = contact->getNext();
128                 i++;
129         }
130 }