File: NewProjTab.cpp

package info (click to toggle)
httraqt 1.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,780 kB
  • sloc: cpp: 7,970; sh: 177; makefile: 13
file content (364 lines) | stat: -rw-r--r-- 9,875 bytes parent folder | download | duplicates (4)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/***************************************************************************
 * C++ Implementation:                                                     *
 * Copyright (C) 2012-2017 by Eduard Kalinowski                            *
 * Germany, Lower Saxony, Hanover                                          *
 * eduard_kalinowski@yahoo.de                                              *
 *                                                                         *
 * HTTraQt is free software; may be distributed and/or modified under the  *
 * terms of the GNU General Public License version 3 as published by the   *
 * Free Software Foundation and appearing in the file LICENSE_GPLv3        *
 * included in the packaging of this file.                                 *
 *                                                                         *
 * This program is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 * GNU General Public License for more details.                            *
 *                                                                         *
 * You should have received a copy of the GNU Lesser General Public        *
 * License along with HTTraQt. If not, see  http://www.gnu.org/licenses    *
 ***************************************************************************/

#include <QtGui>
#include <QFileDialog>
#include <unistd.h>


#include "includes/NewProjTab.h"
#include "../version.h"


NewProjTab::NewProjTab(QWidget* parent, Qt::WindowFlags fl)
    : QWidget(parent, fl)
{

    setupUi(this);

    this->parent = static_cast<HTTraQt*>(parent);

    label02->setEnabled(false);    // project category disabled
    comboProjCat->setEnabled(false);    // selection too

    //     setStyleSheet(this->parent->programStyleSheet);

    connect(editBasePath, SIGNAL(textChanged(QString)), this, SLOT(workDirChanged()));
    connect(comboProjName->lineEdit(), SIGNAL(returnPressed()), this, SLOT(projectInfoEntered()));
    connect(comboProjName, SIGNAL(activated(int)), this, SLOT(projectInfoSelected()));
    connect(label1228, SIGNAL(clicked()), this, SLOT(onBrowseProject()));
}


void NewProjTab::translateTab(void)
{
    setMinimumSize(410, 250);

    if (parent->programStyleSheet.length() > 0) {
        setStyleSheet(parent->programStyleSheet);
    }

    label01->setText(translate(_PROJNAME));
    label02->setText(translate(_PROJCAT));
    label04->setText(translate(_BASEPATH));
    label03->setText(translate(_TYPENEWPROJ));
}


NewProjTab::~NewProjTab()
{
    //   cout << "will be deleted" << endl;
}


void NewProjTab::resizeEvent(QResizeEvent *event)
{
}

bool NewProjTab::testIt()
{
    QString baseDir = editBasePath->text();

    if (baseDir.length() <= 0) {
        MessageBox::exec(this, translate(_NODIR), translate(_TYPENEWPROJ), QMessageBox::Critical);
        return (false);
    }

    QDir verz(baseDir);

    if (verz.exists() == false) {
        if (verz.mkdir(baseDir) == false) {
            MessageBox::exec(this, translate(_CREATEERR), translate(_CANOTCREATEDIR), QMessageBox::Critical);

            return (false);
        }
    }

    parent->currentWorkDir = baseDir;

    QString projName = comboProjName->currentText();

    if (projName.length() <= 0) {
        MessageBox::exec(this, translate(_NOPROJ), translate(_TYPENEWPROJ), QMessageBox::Critical);

        return (false);
    }

    QString newPrDir = baseDir + "/" + projName + "/hts-cache/";
    parent->currentProject = projName;
    //     qDebug() << "new projtab" << projName;

    QDir dr(newPrDir);

    if (dr.exists() == false) {
        if (dr.mkpath(newPrDir) == false) {
            MessageBox::exec(this, translate(_CREATEERR), translate(_CANOTCREATEDIR), QMessageBox::Critical);

            return false;
        }
    }

    parent->getOptions();

    parent->writeSettings(false);

    parent->setWindowTitle(QString(PROGRAM_NAME) +  " v." + HTTQTVERSION + " , " + translate(_PROJ) + ": " + parent->currentProject);

    return (true);
}


void NewProjTab::rebuildDirList()
{
    currentsubdirs.clear();
    comboProjName->clear();

    QFileInfoList finfolist;
    QDir dr(parent->currentWorkDir);
    dr.setNameFilters(QStringList("*"));
    dr.setFilter(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    finfolist = dr.entryInfoList();

    for (int i = 0; i < finfolist.size(); ++i) {
        QString tmpNm =  finfolist.at(i).fileName();

        if (QFile::exists(parent->currentWorkDir + "/" + tmpNm + "/linprofile.ini") == true ||
                QFile::exists(parent->currentWorkDir + "/" + tmpNm + "/hts-cache/winprofile.ini") == true ) {
            currentsubdirs << tmpNm;
        }
    }

    if (editedName.size() > 0) {
        if (currentsubdirs.indexOf(editedName) == -1) {
            currentsubdirs << editedName;
        }
    }

    if (currentsubdirs.size() > 0) {
        int ind;
        comboProjName->setDuplicatesEnabled(false);
        comboProjName->addItems(currentsubdirs);
        ind = comboProjName->findText(editedName);

        if (ind >= 0) {
            comboProjName->setCurrentIndex(ind);
        }
    }
}


void NewProjTab::onBrowseProject()
{
    QString t = editBasePath->text();

    if (t.length() < 1) {
        t = parent->currentWorkDir;
    }

    QString s = QFileDialog::getExistingDirectory(this, translate(_SELECTPATH), t,
                QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks/* |  QFileDialog::DontUseNativeDialog*/);


    if (s.length() <= 0) {
        return;
    }

    QDir dd(s);

    if (dd.exists() == false) {
        return;
    }

    parent->currentWorkDir = s;

    parent->writeSettings(true);

    editBasePath->setText(s);

    parent->dirView->reset();

    parent->dirView->setRootIndex(parent->dModel.index(s));

    editedName = "";

    rebuildDirList();
}


void NewProjTab::workDirChanged()
{
    QString dr = editBasePath->text();
    QDir d(dr);

    if (d.exists() == false) {
        return;
    }

    rebuildDirList();

    parent->dirView->setRootIndex(parent->dModel.index(dr));
}

#if 0
void NewProjTab::onSelectBatchFile()
{
    QFileDialog* fd;
    int sz = parent->systemFont.pointSize();
    QString sSheet;
    sSheet = QString().sprintf("font-size: %dpt", sz);

    if ( sz == -1) {
        sz = parent->systemFont.pixelSize();
        sSheet = QString().sprintf("font-size: %dpx", sz);
    }

    setStyleSheet(sSheet);

    fd = new QFileDialog(this, translate("Choose a file"), parent->currentWorkDir, "Text (*.txt)");
    //     fd->setFont(parent->systemFont);
    //     fd->exec();
    QString s = fd->getOpenFileName();//QFileDialog::getOpenFileName(this, translate("Choose a file"), parent->currentWorkDir, "Text (*.txt)");
}
#endif

void NewProjTab::projectInfoEntered()
{
    QString temp = comboProjName->currentText();

    editedName = temp;
}

void NewProjTab::selectProj(const QString &name)
{
    int pos = comboProjName->findText(name);

    if (pos >= 0) {
        comboProjName->setCurrentIndex(pos);
        emit projectInfoSelected();
    }
}

void NewProjTab::projectInfoSelected()
{
    bool exists = false;

    //     disconnect(editBasePath, SIGNAL(textChanged (QString)), this, SLOT(projectInfoSelected()));

    QString temp = comboProjName->currentText();

    editedName = temp;

    parent->currentProject = temp;

    QString fileName = parent->currentWorkDir + "/" + temp;
    QDir dir = fileName;

    if (QFile::exists(fileName + "/linprofile.ini")) {
        if (dir.exists() == true) {
            exists = true;
        }
    }

    if (QFile::exists(fileName + "/hts-cache/winprofile.ini")) {
        if (dir.exists() == true) {
            exists = true;
        }
    }

    if (exists == false) {
        //         parent->readSettings(true);
        label03->setText(translate(_NEWPROJECT));

    } else {
        label03->setText(translate(_TYPENEWPROJ));
    }

    parent->getOptions();

    changeProjname(fileName);

    //     connect(editBasePath, SIGNAL(textChanged (QString)), this, SLOT(projectInfoSelected()));
}

void NewProjTab::onDirChanged()
{
    QString dir = editBasePath->text();
    QDir dd(dir);

    if (dd.exists() == true) {
        // opren dir in file browser
        rebuildDirList();
    }
}


void NewProjTab::changeProjname(QString stl)      //kompletter name
{
    QString st;
    bool found = false;
    QString tempName;
    //

    if (stl.length() == 0 || stl.length() > HTS_URLMAXSIZE) {
        label03->setText(translate(_TYPENEWPROJ));
        label01->setText(translate(_PROJNAME));
    } else {
        st = editBasePath->text(); // current Directory

        tempName = (stl + "/linprofile.ini");

        QFile setlin(tempName);

        if (setlin.exists() == true  &&  // un cache est pr�sent
                (setlin.size()) > 0) {      // taille log contr�le>0
            found = true;
        } else {
            tempName = (stl + "/hts-cache/winprofile.ini");
            QFile setwin(tempName);

            if (setwin.exists() == true  &&  // un cache est pr�sent
                    (setwin.size()) > 0) {      // taille log contr�le>0
                found = true;
            }
        }

        if (found == false) {
            //             parent->readSettings(true);
            label03->setText(translate(_NEWPROJECT));
            label01->setText(translate(_NEWPROJNAME));
            //      parent->m_todo = 0;
        } else {
            parent->GetProfile("CurrentUrl", st);
            parent->GetProfile("Category", stl);
            //
            label03->setText(st);
            label01->setText(translate(_PROJNAME));
        }

    }

    parent->currentOptionsFile = tempName;

    rebuildDirList();
}