|
1 #include <qmainwindow.h> |
|
2 #include <qmessagebox.h> |
|
3 #include <qstatusbar.h> |
|
4 #include <qapplication.h> |
|
5 #include <qsqldatabase.h> |
|
6 #include <qmenubar.h> |
|
7 #include <qpopupmenu.h> |
|
8 #include <qapplication.h> |
|
9 #include <qvbox.h> |
|
10 #include <qlabel.h> |
|
11 #include <qlayout.h> |
|
12 #include <qlineedit.h> |
|
13 #include <qpushbutton.h> |
|
14 #include <qworkspace.h> |
|
15 #include <qdialog.h> |
|
16 #include "mainpanel.h" |
|
17 #include "chartwindow.h" |
|
18 #include "dbconfigureform.h" |
|
19 #include "infolabel.h" |
|
20 |
|
21 |
|
22 MainPanel::MainPanel( QWidget *parent, const char *name ) |
|
23 : QMainWindow( parent, name ) |
|
24 { |
|
25 // Initialize the Menu bar |
|
26 QPopupMenu *file = new QPopupMenu( this ); |
|
27 QPopupMenu *actions = new QPopupMenu( this ); |
|
28 QPopupMenu *database = new QPopupMenu( this ); |
|
29 |
|
30 database->insertItem( tr("&Connect"), this, |
|
31 SLOT(dbConnect())); |
|
32 database->insertItem( tr("&Disconnect"), this, |
|
33 SLOT(dbDisconnect())); |
|
34 database->insertSeparator(); |
|
35 database->insertItem( tr("Confi&gure"), this, |
|
36 SLOT(dbConfigure())); |
|
37 |
|
38 file->insertItem( tr("&Quit"), qApp, |
|
39 SLOT(quit()), |
|
40 tr("Ctrl+Q", "Quit")); |
|
41 |
|
42 actions->insertItem( tr("&Chart of Accounts"), this, |
|
43 SLOT(accountChart()), |
|
44 tr("Ctrl+C", "Action: Chart of Accounts")); |
|
45 actions->insertItem( tr("&Transactions"), this, |
|
46 SLOT(transactions()), |
|
47 tr("Ctrl+T", "Action: Transactions")); |
|
48 |
|
49 menuBar()->insertItem( tr("&File"), file ); |
|
50 menuBar()->insertItem( tr("&Actions"), actions ); |
|
51 menuBar()->insertItem( tr("&Data Base"), database ); |
|
52 |
|
53 // Initialize the database configuration |
|
54 db_config.host = "localhost"; |
|
55 db_config.username = "yagl_user"; |
|
56 db_config.password = "prova"; |
|
57 db_config.database = "yagl1"; |
|
58 db_config.driver = "QMYSQL3"; |
|
59 |
|
60 // Initialize this window (main) |
|
61 setCaption( tr("Yet Another GUI Ledger") ); |
|
62 |
|
63 |
|
64 workspace = new QWorkspace( this ); |
|
65 |
|
66 setCentralWidget(workspace); |
|
67 |
|
68 // Status Bar |
|
69 info_connected = new InfoLabel( tr("Database"), |
|
70 tr("disconnected"), this ); |
|
71 statusBar()->addWidget( info_connected ); |
|
72 |
|
73 // Database pointer |
|
74 our_database = NULL; |
|
75 |
|
76 // Dialog pointers |
|
77 chartW = NULL; |
|
78 |
|
79 } |
|
80 |
|
81 void MainPanel::transactions( ) |
|
82 { |
|
83 /* |
|
84 if (!transactionsD) |
|
85 transactionsD = new InfoLabel( tr("Prova"), |
|
86 tr("Transactions"), workspace); |
|
87 */ |
|
88 } |
|
89 |
|
90 void MainPanel::accountChart( ) |
|
91 { |
|
92 if (chartW==NULL) |
|
93 { |
|
94 chartW = new ChartWindow(workspace); |
|
95 chartW->show(); |
|
96 connect(chartW, SIGNAL(destroyed()), this, |
|
97 SLOT(accountChartRemoved())); |
|
98 } |
|
99 qDebug("end of try to opening chartW"); |
|
100 } |
|
101 |
|
102 void MainPanel::accountChartRemoved( ) |
|
103 { |
|
104 chartW = NULL; |
|
105 qDebug("chartW to null."); |
|
106 } |
|
107 |
|
108 void MainPanel::dbConnect( ) |
|
109 { |
|
110 our_database = QSqlDatabase::addDatabase( db_config.driver ); |
|
111 our_database->setDatabaseName( db_config.database ); |
|
112 our_database->setUserName( db_config.username ); |
|
113 our_database->setPassword( db_config.password ); |
|
114 our_database->setHostName( db_config.host ); |
|
115 |
|
116 /* |
|
117 // Do we really need that ??!??!!? |
|
118 if ( db_config.driver == "QMYSQL3" ) |
|
119 our_database->setPort(3306); |
|
120 */ |
|
121 |
|
122 qWarning( "Opening database connection..." ); |
|
123 |
|
124 if ( !our_database->open() ) |
|
125 { |
|
126 QString error_text( |
|
127 tr("Database could not connect.\n Driver: ", |
|
128 "db_connect_error_text") |
|
129 + our_database->lastError().driverText() |
|
130 + tr("\n Database: ", "db_connect_errortext") + |
|
131 our_database->lastError().databaseText()); |
|
132 |
|
133 qWarning( error_text ); |
|
134 QMessageBox::warning( this, tr("Database connection error"), |
|
135 error_text, |
|
136 QMessageBox::Ok || QMessageBox::Default, |
|
137 QMessageBox::NoButton, |
|
138 QMessageBox::NoButton); |
|
139 } |
|
140 else |
|
141 { |
|
142 qWarning( " connection opened." ); |
|
143 // Let the status bar know |
|
144 info_connected->setValue("connected"); |
|
145 } |
|
146 |
|
147 } |
|
148 |
|
149 void MainPanel::dbDisconnect( ) |
|
150 { |
|
151 if (our_database) |
|
152 { |
|
153 qWarning( "Closing database connection..." ); |
|
154 our_database->close(); |
|
155 qWarning( " connection closed." ); |
|
156 // Let the status bar know |
|
157 info_connected->setValue("disconnected"); |
|
158 |
|
159 } |
|
160 else |
|
161 qWarning( "We're not connected" ); |
|
162 } |
|
163 |
|
164 |
|
165 void MainPanel::dbConfigure( ) |
|
166 { |
|
167 DBConfigureForm form(&db_config, this ); |
|
168 |
|
169 form.exec(); |
|
170 } |