-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreemain.cpp
137 lines (106 loc) · 3.56 KB
/
treemain.cpp
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
/* Treecle
*
* Copyright (c) Kartik Patel
* E-mail: [email protected]
* Download from: https://letapk.wordpress.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*/
#include "treecle.h"
QString userpath;
QString Lockfilename;
void check_qtdata_dir ();
bool check_lockfile(void);
void create_lockfile ();
void delete_lockfile ();
int main(int argc, char *argv[])
//start user-interface
{
bool ok = false;
Q_INIT_RESOURCE(treecle);
QApplication app(argc, argv);
QTranslator appTranslator;
appTranslator.load("treecle_" + QLocale::system().name(), qApp->applicationDirPath());
app.installTranslator(&appTranslator);
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), qApp->applicationDirPath());
app.installTranslator(&qtTranslator);
//get the path to the user's home directory
userpath.clear();
userpath.append (getenv ("HOME"));
userpath.append("/.treecle");//home/{account-name}/.treecle
Lockfilename.append(userpath);
Lockfilename.append("/treelockfile.lck");
ok = check_lockfile ();
if (ok == false)//lockfile present, exit
return 0;
create_lockfile();
//check for the tdj data directory and create it if required
check_qtdata_dir();
MainWindow mainwindow;
mainwindow.setWindowTitle(QObject::tr("Treecle"));
mainwindow.show();
return app.exec();
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
//set up the user-interface
{
//initial window size
this->setMinimumHeight(300);
this->setMinimumWidth(700);
//menu, and two toolbars
setup_menu_and_toolbar();
//splitter for the tree and editor
splitter = new QSplitter(this);
//Tree and HTML editor windows are within the splitter
//tree window on the left
tree = new QTreeWidget ();
tree->setColumnCount(1);
tree->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
connect (tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(set_branch (QTreeWidgetItem *)));
tree->setHeaderLabel(tr("Filename"));
//HTML editor on right
leafview = new QWebView ();
leafview->page()->setContentEditable(true);
leafview->page()->settings()->setDefaultTextEncoding("UTF-8");
connect (leafview->page(), SIGNAL(contentsChanged()), this, SLOT(get_data_from_leaf()));
connect(leafview->pageAction(QWebPage::ToggleBold), SIGNAL(changed()), SLOT(adjustActions()));
splitter->addWidget(tree);
splitter->addWidget(leafview);
//status bar on the bottom
statustext = new QLabel (this);
statustext->setText(tr("Status messages appear here"));
statustext->setFrameStyle(QFrame::Plain);
statustext->setAlignment(Qt::AlignBottom);
catflag = 1;
//set the Homepath
Homepath.append(userpath);
//set the working directory to the data subdirectory
QDir::setCurrent(Homepath);
//help file to read
Helpfilename.append (userpath);
Helpfilename.append ("/treeclehelp.pdf");
//"COPYING" file to read
Gnugplfilename.append (userpath);
Gnugplfilename.append ("/COPYING");
//Currentfile name
Currentfile.append("Noname.trc");
//initial window size
this->resize(990,630);
//read the user's preferences
readprefs();
this->setFocus();
}
MainWindow::~MainWindow()
{
delete_lockfile();
}
void MainWindow::quit()
{
delete_lockfile();
MainWindow::close();
}