summaryrefslogtreecommitdiff
path: root/noncore/apps/checkbook/qcheckbook.cpp
blob: bb7a5acb5aed3a0465a1f970928dbb5dbf32d7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "qcheckbook.h"

#include <qmenubar.h>
#include <qstatusbar.h>
#include <qpopupmenu.h>
#include <qapplication.h>
#include <qfile.h>
#include <qdir.h>

QCheckBook::QCheckBook()
  : QMainWindow(),
  m_view(),
  m_view2(),
  m_view3()
{
  initCheck = false;
  initMM = false;
  setCaption("Checking");
  statusBar()->hide();
  menuBar()->hide();

  bar = new QToolBar(this);
  bar->setHorizontalStretchable( TRUE );

  addToolBar(bar);

  Config config("qcheckbook");
  config.setGroup("Global");
  QString lastCheck = config.readEntry("LastCheckBook", QString(""));

  QString checkdirname = QDir::homeDirPath();
  checkdirname.append("/.checkbooks/");
  checkdirname.append(lastCheck);
  QFile f(checkdirname);


  if (lastCheck.isEmpty() == false && lastCheck != "" && f.exists() == true)
  {
    newCheck(lastCheck);
  } else {
    initMainMenus();
  }

  setToolBarsMovable( FALSE );
}

void QCheckBook::newCheck(const QString &filename)
{
  if (filename.isEmpty() == false)
  {
    initCheck = true;
    if (m_view != 0)
    {
      m_view=0;
      delete m_view;
    }
    m_view = new QCheckView(this, filename);
    m_view->hide();
    connect(m_view, SIGNAL(reload(const QString &)), this, SLOT(newCheck(const QString &)));
    if (initMM == true)
    {
      delete nb1;
    }
    bar->clear();
    mbar = new QMenuBar(bar);
    mbar->setMargin(0);

    QPixmap newIcon = Resource::loadPixmap( "new" );
    nb2 = new QToolButton( newIcon, "New", QString::null, m_view, SLOT(newClicked()), bar, "new item" );
    QPixmap pixmap = Resource::loadPixmap( "pixmap" );
    m_filename = filename;
    nb3 = new QToolButton( pixmap, "Graph", QString::null, this, SLOT(newGraph()), bar, "new graph" );

    QPixmap closeIcon = Resource::loadPixmap( "close" );
    nb4 = new QToolButton( closeIcon, "Close", QString::null, this, SLOT(initMainMenus()), bar, "close graph" );

    popup = new QPopupMenu(m_view);
    popup->insertItem("&New Entry", m_view, SLOT(newClicked()));
    popup->insertItem("&Graph Checkbook", this, SLOT(newGraph()));
    popup->insertItem("&Close Checkbook", this, SLOT(initMainMenus()));
    popup->insertItem("&Exit", this, SLOT(close()));
    mbar->insertItem("&File", popup);

    setCentralWidget(m_view);
    m_view->show();

    Config config("qcheckbook");
    config.setGroup("Global");
    config.writeEntry("LastCheckBook", filename);
    initMM = false;
  }
}

void QCheckBook::close()
{
  QApplication::exit();
}

void QCheckBook::newGraph()
{
  if (m_filename.isEmpty() == false)
  {
    m_view2 = new QCheckGraph(m_filename);
    m_view2->showMaximized();
  }
}

void QCheckBook::initMainMenus()
{
  Config config("qcheckbook");
  config.setGroup("Global");
  config.writeEntry("LastCheckBook", QString(""));
  initMM = true;
  m_filename = "";
  if (m_view3 != 0)
  {
    delete m_view3;
  }
  m_view3 = new QCheckMainMenu(this);
  m_view3->hide();

  if (initCheck == true)
  {
    delete nb2;
    delete nb3;
    delete nb4;
  }

  bar->clear();

  mbar = new QMenuBar(bar);
  mbar->setMargin(0);

  QPixmap newIcon = Resource::loadPixmap( "new" );
  nb1 = new QToolButton( newIcon, "New", QString::null, m_view3, SLOT(newClicked()), bar, "new book" );

  popup = new QPopupMenu();
  popup->insertItem("&New", m_view3, SLOT(newClicked()));
  popup->insertItem("&Exit", this, SLOT(close()));
  mbar->insertItem("&File", popup);

  setCentralWidget(m_view3);
  m_view3->show();

  connect(m_view3, SIGNAL(itemSelected(const QString &)), this, SLOT(newCheck(const QString &)));
  initCheck = false;
}