--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mainpanel.cpp Thu May 18 23:05:01 2006 +0200
@@ -0,0 +1,170 @@
+#include <qmainwindow.h>
+#include <qmessagebox.h>
+#include <qstatusbar.h>
+#include <qapplication.h>
+#include <qsqldatabase.h>
+#include <qmenubar.h>
+#include <qpopupmenu.h>
+#include <qapplication.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qworkspace.h>
+#include <qdialog.h>
+#include "mainpanel.h"
+#include "chartwindow.h"
+#include "dbconfigureform.h"
+#include "infolabel.h"
+
+
+MainPanel::MainPanel( QWidget *parent, const char *name )
+ : QMainWindow( parent, name )
+{
+ // Initialize the Menu bar
+ QPopupMenu *file = new QPopupMenu( this );
+ QPopupMenu *actions = new QPopupMenu( this );
+ QPopupMenu *database = new QPopupMenu( this );
+
+ database->insertItem( tr("&Connect"), this,
+ SLOT(dbConnect()));
+ database->insertItem( tr("&Disconnect"), this,
+ SLOT(dbDisconnect()));
+ database->insertSeparator();
+ database->insertItem( tr("Confi&gure"), this,
+ SLOT(dbConfigure()));
+
+ file->insertItem( tr("&Quit"), qApp,
+ SLOT(quit()),
+ tr("Ctrl+Q", "Quit"));
+
+ actions->insertItem( tr("&Chart of Accounts"), this,
+ SLOT(accountChart()),
+ tr("Ctrl+C", "Action: Chart of Accounts"));
+ actions->insertItem( tr("&Transactions"), this,
+ SLOT(transactions()),
+ tr("Ctrl+T", "Action: Transactions"));
+
+ menuBar()->insertItem( tr("&File"), file );
+ menuBar()->insertItem( tr("&Actions"), actions );
+ menuBar()->insertItem( tr("&Data Base"), database );
+
+ // Initialize the database configuration
+ db_config.host = "localhost";
+ db_config.username = "yagl_user";
+ db_config.password = "prova";
+ db_config.database = "yagl1";
+ db_config.driver = "QMYSQL3";
+
+ // Initialize this window (main)
+ setCaption( tr("Yet Another GUI Ledger") );
+
+
+ workspace = new QWorkspace( this );
+
+ setCentralWidget(workspace);
+
+ // Status Bar
+ info_connected = new InfoLabel( tr("Database"),
+ tr("disconnected"), this );
+ statusBar()->addWidget( info_connected );
+
+ // Database pointer
+ our_database = NULL;
+
+ // Dialog pointers
+ chartW = NULL;
+
+}
+
+void MainPanel::transactions( )
+{
+ /*
+ if (!transactionsD)
+ transactionsD = new InfoLabel( tr("Prova"),
+ tr("Transactions"), workspace);
+ */
+}
+
+void MainPanel::accountChart( )
+{
+ if (chartW==NULL)
+ {
+ chartW = new ChartWindow(workspace);
+ chartW->show();
+ connect(chartW, SIGNAL(destroyed()), this,
+ SLOT(accountChartRemoved()));
+ }
+ qDebug("end of try to opening chartW");
+}
+
+void MainPanel::accountChartRemoved( )
+{
+ chartW = NULL;
+ qDebug("chartW to null.");
+}
+
+void MainPanel::dbConnect( )
+{
+ our_database = QSqlDatabase::addDatabase( db_config.driver );
+ our_database->setDatabaseName( db_config.database );
+ our_database->setUserName( db_config.username );
+ our_database->setPassword( db_config.password );
+ our_database->setHostName( db_config.host );
+
+ /*
+ // Do we really need that ??!??!!?
+ if ( db_config.driver == "QMYSQL3" )
+ our_database->setPort(3306);
+ */
+
+ qWarning( "Opening database connection..." );
+
+ if ( !our_database->open() )
+ {
+ QString error_text(
+ tr("Database could not connect.\n Driver: ",
+ "db_connect_error_text")
+ + our_database->lastError().driverText()
+ + tr("\n Database: ", "db_connect_errortext") +
+ our_database->lastError().databaseText());
+
+ qWarning( error_text );
+ QMessageBox::warning( this, tr("Database connection error"),
+ error_text,
+ QMessageBox::Ok || QMessageBox::Default,
+ QMessageBox::NoButton,
+ QMessageBox::NoButton);
+ }
+ else
+ {
+ qWarning( " connection opened." );
+ // Let the status bar know
+ info_connected->setValue("connected");
+ }
+
+}
+
+void MainPanel::dbDisconnect( )
+{
+ if (our_database)
+ {
+ qWarning( "Closing database connection..." );
+ our_database->close();
+ qWarning( " connection closed." );
+ // Let the status bar know
+ info_connected->setValue("disconnected");
+
+ }
+ else
+ qWarning( "We're not connected" );
+}
+
+
+void MainPanel::dbConfigure( )
+{
+ DBConfigureForm form(&db_config, this );
+
+ form.exec();
+}