comparison settingsdialog.cpp @ 0:a9098eba2ee5

Initial commit.
author Jari Korhonen <jtkorhonen@gmail.com>
date Thu, 22 Apr 2010 03:15:35 +0300
parents
children e275d0b5d6ca
comparison
equal deleted inserted replaced
-1:000000000000 0:a9098eba2ee5
1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl)
2
3 #include "settingsdialog.h"
4
5 #include <QHBoxLayout>
6 #include <QVBoxLayout>
7
8
9 SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
10 {
11 QPushButton *okButton;
12 QPushButton *cancelButton;
13
14 mainWnd = (MainWindow *) parent;
15
16 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
17 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
18 userInfoLabel -> setBuddy(userInfoLineEdit);
19
20 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
21 remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath);
22 remoteRepoLabel -> setBuddy(remoteRepoLineEdit);
23 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
24
25 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
26 workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath);
27 workFolderLabel -> setBuddy(workFolderLineEdit);
28 workFolderBrowseButton = new QPushButton(tr("Browse..."));
29
30 okButton = new QPushButton(tr("Ok"));
31 cancelButton = new QPushButton(tr("Cancel"));
32
33 QHBoxLayout *btnLayout = new QHBoxLayout;
34 btnLayout -> addWidget(okButton);
35 btnLayout -> addWidget(cancelButton);
36 btnLayout -> addStretch();
37
38 QHBoxLayout *workFolderLayout = new QHBoxLayout;
39 workFolderLayout -> addWidget(workFolderLineEdit);
40 workFolderLayout -> addWidget(workFolderBrowseButton);
41
42 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
43 remoteRepoLayout -> addWidget(remoteRepoLineEdit);
44 remoteRepoLayout -> addWidget(remoteRepoBrowseButton);
45
46 QVBoxLayout *mainLayout = new QVBoxLayout;
47
48 mainLayout -> addWidget(userInfoLabel);
49 mainLayout -> addWidget(userInfoLineEdit);
50
51 mainLayout -> addWidget(remoteRepoLabel);
52 mainLayout -> addLayout(remoteRepoLayout);
53
54 mainLayout -> addWidget(workFolderLabel);
55 mainLayout -> addLayout(workFolderLayout);
56
57 mainLayout -> addLayout(btnLayout);
58
59 setLayout(mainLayout);
60
61 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
62 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
63 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
64 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
65 }
66
67 #define EMPTY_DIR 2
68
69 void SettingsDialog::okClicked()
70 {
71 mainWnd -> firstStart = false;
72 mainWnd -> userInfo = userInfoLineEdit->text();
73 mainWnd -> remoteRepoPath = remoteRepoLineEdit->text();
74 mainWnd -> workFolderPath = workFolderLineEdit -> text();
75 mainWnd -> writeSettings();
76 mainWnd -> enableDisableActions();
77 mainWnd -> hgStat();
78 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
79
80 QDir dir(mainWnd -> workFolderPath);
81 if (dir.exists(mainWnd -> workFolderPath))
82 {
83 uint cnt = dir.count();
84 if (cnt == EMPTY_DIR)
85 {
86 QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is empty.\nChoose \"File/Clone from remote\"\nto download a remote repository.\nYou can also choose \"File/Init local repository\"\nto initialize repository and add files later."));
87 }
88 else
89 {
90 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
91 QDir repoDir(repoPath);
92 if (!repoDir.exists())
93 {
94 QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is not empty,\nbut does not yet contain a repository.\nChoose \"File/Init local repository\" \nto initialize repository."));
95 }
96 }
97 }
98
99
100 close();
101 }
102
103
104 void SettingsDialog::cancelClicked()
105 {
106 close();
107 }
108
109
110 void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit)
111 {
112 QString dir;
113 QString startDir;
114 QString system;
115
116 system = getSystem();
117 if ((system == "Linux") || (system == "Mac"))
118 {
119 startDir = QDir::homePath();
120 }
121 else
122 {
123 startDir = "c:\\";
124 }
125
126 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
127 startDir,
128 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
129
130 lineEdit->setText(dir + QDir::separator());
131 }
132
133 void SettingsDialog::browseWorkFolder()
134 {
135 browseDirAndSetLineEdit(workFolderLineEdit);
136 }
137
138 void SettingsDialog::browseRemoteRepo()
139 {
140 browseDirAndSetLineEdit(remoteRepoLineEdit);
141 }
142
143