annotate settingsdialog.cpp @ 22:465fbf9ad5a9

Tries to show hg serve ipv6 address correctly (at least for browser, dont know about hg itself).
author Jari Korhonen <jtkorhonen@gmail.com>
date Tue, 18 May 2010 23:56:20 +0300
parents e376d572b0c4
children 45bfb8dc1faf
rev   line source
jtkorhonen@0 1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl)
jtkorhonen@0 2
jtkorhonen@0 3 #include "settingsdialog.h"
jtkorhonen@0 4
jtkorhonen@0 5 #include <QHBoxLayout>
jtkorhonen@0 6 #include <QVBoxLayout>
jtkorhonen@0 7
jtkorhonen@0 8 SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
jtkorhonen@0 9 {
jtkorhonen@0 10 QPushButton *okButton;
jtkorhonen@0 11 QPushButton *cancelButton;
jtkorhonen@0 12
jtkorhonen@0 13 mainWnd = (MainWindow *) parent;
jtkorhonen@0 14
jtkorhonen@0 15 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
jtkorhonen@0 16 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
jtkorhonen@0 17 userInfoLabel -> setBuddy(userInfoLineEdit);
jtkorhonen@0 18
jtkorhonen@0 19 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
jtkorhonen@0 20 remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath);
jtkorhonen@0 21 remoteRepoLabel -> setBuddy(remoteRepoLineEdit);
jtkorhonen@0 22 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 23
jtkorhonen@0 24 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
jtkorhonen@0 25 workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath);
jtkorhonen@0 26 workFolderLabel -> setBuddy(workFolderLineEdit);
jtkorhonen@0 27 workFolderBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 28
jtkorhonen@0 29 okButton = new QPushButton(tr("Ok"));
jtkorhonen@0 30 cancelButton = new QPushButton(tr("Cancel"));
jtkorhonen@0 31
jtkorhonen@0 32 QHBoxLayout *btnLayout = new QHBoxLayout;
jtkorhonen@0 33 btnLayout -> addWidget(okButton);
jtkorhonen@0 34 btnLayout -> addWidget(cancelButton);
jtkorhonen@0 35 btnLayout -> addStretch();
jtkorhonen@0 36
jtkorhonen@0 37 QHBoxLayout *workFolderLayout = new QHBoxLayout;
jtkorhonen@0 38 workFolderLayout -> addWidget(workFolderLineEdit);
jtkorhonen@0 39 workFolderLayout -> addWidget(workFolderBrowseButton);
jtkorhonen@0 40
jtkorhonen@0 41 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
jtkorhonen@0 42 remoteRepoLayout -> addWidget(remoteRepoLineEdit);
jtkorhonen@0 43 remoteRepoLayout -> addWidget(remoteRepoBrowseButton);
jtkorhonen@0 44
jtkorhonen@0 45 QVBoxLayout *mainLayout = new QVBoxLayout;
jtkorhonen@0 46
jtkorhonen@0 47 mainLayout -> addWidget(userInfoLabel);
jtkorhonen@0 48 mainLayout -> addWidget(userInfoLineEdit);
jtkorhonen@0 49
jtkorhonen@0 50 mainLayout -> addWidget(remoteRepoLabel);
jtkorhonen@0 51 mainLayout -> addLayout(remoteRepoLayout);
jtkorhonen@0 52
jtkorhonen@0 53 mainLayout -> addWidget(workFolderLabel);
jtkorhonen@0 54 mainLayout -> addLayout(workFolderLayout);
jtkorhonen@0 55
jtkorhonen@0 56 mainLayout -> addLayout(btnLayout);
jtkorhonen@0 57
jtkorhonen@0 58 setLayout(mainLayout);
jtkorhonen@0 59
jtkorhonen@0 60 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
jtkorhonen@0 61 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
jtkorhonen@0 62 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
jtkorhonen@0 63 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
jtkorhonen@0 64 }
jtkorhonen@0 65
jtkorhonen@0 66 #define EMPTY_DIR 2
jtkorhonen@0 67
jtkorhonen@0 68 void SettingsDialog::okClicked()
jtkorhonen@0 69 {
jtkorhonen@0 70 mainWnd -> firstStart = false;
jtkorhonen@0 71 mainWnd -> userInfo = userInfoLineEdit->text();
jtkorhonen@0 72 mainWnd -> remoteRepoPath = remoteRepoLineEdit->text();
jtkorhonen@9 73
jtkorhonen@0 74 mainWnd -> workFolderPath = workFolderLineEdit -> text();
jtkorhonen@9 75 if (!mainWnd -> workFolderPath.endsWith(QDir::separator()))
jtkorhonen@9 76 {
jtkorhonen@9 77 mainWnd -> workFolderPath += QDir::separator();
jtkorhonen@9 78 }
jtkorhonen@9 79
jtkorhonen@0 80 mainWnd -> writeSettings();
jtkorhonen@0 81 mainWnd -> enableDisableActions();
jtkorhonen@0 82 mainWnd -> hgStat();
jtkorhonen@0 83 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
jtkorhonen@0 84
jtkorhonen@0 85 QDir dir(mainWnd -> workFolderPath);
jtkorhonen@0 86 if (dir.exists(mainWnd -> workFolderPath))
jtkorhonen@0 87 {
jtkorhonen@0 88 uint cnt = dir.count();
jtkorhonen@0 89 if (cnt == EMPTY_DIR)
jtkorhonen@0 90 {
jtkorhonen@0 91 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."));
jtkorhonen@0 92 }
jtkorhonen@0 93 else
jtkorhonen@0 94 {
jtkorhonen@0 95 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
jtkorhonen@0 96 QDir repoDir(repoPath);
jtkorhonen@0 97 if (!repoDir.exists())
jtkorhonen@0 98 {
jtkorhonen@0 99 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."));
jtkorhonen@0 100 }
jtkorhonen@0 101 }
jtkorhonen@0 102 }
jtkorhonen@0 103
jtkorhonen@0 104
jtkorhonen@0 105 close();
jtkorhonen@0 106 }
jtkorhonen@0 107
jtkorhonen@0 108
jtkorhonen@0 109 void SettingsDialog::cancelClicked()
jtkorhonen@0 110 {
jtkorhonen@0 111 close();
jtkorhonen@0 112 }
jtkorhonen@0 113
jtkorhonen@0 114
jtkorhonen@0 115 void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit)
jtkorhonen@0 116 {
jtkorhonen@0 117 QString dir;
jtkorhonen@0 118 QString startDir;
jtkorhonen@0 119 QString system;
jtkorhonen@0 120
jtkorhonen@0 121 system = getSystem();
jtkorhonen@0 122 if ((system == "Linux") || (system == "Mac"))
jtkorhonen@0 123 {
jtkorhonen@0 124 startDir = QDir::homePath();
jtkorhonen@0 125 }
jtkorhonen@0 126 else
jtkorhonen@0 127 {
jtkorhonen@0 128 startDir = "c:\\";
jtkorhonen@0 129 }
jtkorhonen@0 130
jtkorhonen@0 131 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
jtkorhonen@0 132 startDir,
jtkorhonen@0 133 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
jtkorhonen@0 134
jtkorhonen@0 135 lineEdit->setText(dir + QDir::separator());
jtkorhonen@0 136 }
jtkorhonen@0 137
jtkorhonen@0 138 void SettingsDialog::browseWorkFolder()
jtkorhonen@0 139 {
jtkorhonen@0 140 browseDirAndSetLineEdit(workFolderLineEdit);
jtkorhonen@0 141 }
jtkorhonen@0 142
jtkorhonen@0 143 void SettingsDialog::browseRemoteRepo()
jtkorhonen@0 144 {
jtkorhonen@0 145 browseDirAndSetLineEdit(remoteRepoLineEdit);
jtkorhonen@0 146 }
jtkorhonen@0 147
jtkorhonen@0 148