File: OptionsTab.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 (318 lines) | stat: -rw-r--r-- 8,572 bytes parent folder | download
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
/***************************************************************************
 * 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 "includes/httraqt.h"
#include "includes/OptionsTab.h"
#include "../options/includes/OptionsDialog.h"
#include "includes/InsertUrlDialog.h"

class InsertUrlDialog;

int OptionsTab::hl01[] = { _MOD00, _MOD01, _MOD02, _MOD03, _MOD04, _MOD05, _MOD06};

OptionsTab::OptionsTab(QWidget *parent, Qt::WindowFlags fl)
    : QWidget(parent, fl)
{
    setupUi(this);

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

    comb01 = LISTDEF_10;

    QString tlist = translate(comb01);
    QStringList lCombo = tlist.split("\n");
    comboAction->insertItems(0, lCombo);

    comboAction->setCurrentIndex(0);
    label03_2->setText(translate(hl01[0]));

    connect(label01, SIGNAL(clicked()), this, SLOT(onSetOptions()));
    connect(label04, SIGNAL(clicked()), this, SLOT(onAddURL()));
    connect(label05_2, SIGNAL(clicked()), this, SLOT(onCaptureUrl()));
    connect(label12, SIGNAL(clicked()), this, SLOT(onURLList()));
    connect(comboAction, SIGNAL(activated(int)), this, SLOT(showHelp()));
    connect(textEdit, SIGNAL(textChanged ()), this, SLOT(removeSpaceLines()));
}


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


void OptionsTab::removeSpaceLines()
{
    QStringList sl;
    bool found = false;
    QString t = textEdit->toPlainText();
    sl = t.split("\n");
    t = "";

    foreach(QString entry, sl) {
        if (entry.length() == 0) {
            found = true;
        }
    }

    if (found == false) {
        return;
    }

    disconnect(textEdit, SIGNAL(textChanged ()), this, SLOT(removeSpaceLines()));

    foreach(QString entry, sl) {
        if (entry.length() > 0) {
            t = t + entry + "\n";
        }
    }

    textEdit->setText(t);

    connect(textEdit, SIGNAL(textChanged ()), this, SLOT(removeSpaceLines()));
}


void OptionsTab::onCaptureUrl()
{
    QClipboard *clipboard = QApplication::clipboard();
    QString originalText = clipboard->text();

    originalText = getAndTestUrlString(originalText);

    if (originalText.length() > 0) {
        originalText += "\n";

        QString st = textEdit->toPlainText();
        st = st + originalText;

        textEdit->setText(st);
    } else {
        MessageBox::exec(this, translate(_ERR), translate(_WRONGURLS), QMessageBox::Warning);
    }
}


void OptionsTab::updateLastAction()
{
    QString dirName = parent->currentWorkDir + "/" + parent->currentProject;

    // il existe déja un cache précédent.. renommer
    if (QFile::exists(dirName + "/hts-cache/new.zip") ||
            (QFile::exists(dirName + "/hts-cache/new.dat") && QFile::exists(dirName + "/hts-cache/new.ndx"))) {
        if (!QFile::exists(dirName + "/hts-cache/interrupted.lock") && !QFile::exists(dirName + "/hts-in_progress.lock")) {
            comboAction->setCurrentIndex(LAST_ACTION);
        } else {
            comboAction->setCurrentIndex(LAST_ACTION - 1);
        }
    }
}


QString OptionsTab::getAndTestUrlString(const QString st)
{
    QUrl u(st);

    if (u.isValid() == true) {
        return st;
    }

    return "";
}


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

    // ajust size(hight) to content
    textEdit->setFixedHeight(textEdit->document()->size().height() + textEdit->contentsMargins().top() * 2);


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

    QString tlist = translate(comb01);
    QStringList lCombo = tlist.split("\n");
    comboAction->clear();
    comboAction->insertItems(0, lCombo);

    label05_2->setText(translate(_GETCLIPBOARD));
    label->setText(translate(_CAPTURL));

    label01->setText(translate(_SET_OPT));
    label02->setText(translate(_ACTION));
    label03->setText(translate(_WEB_ADDR));
    label04->setText(translate(_ADD_URL));
    label05->setText(translate(_URLLIST));
    label06->setText(translate(_PREFS_OPT));

    showHelp();
}


void OptionsTab::onAddURL()
{
    InsertUrlDialog* dUrl = new InsertUrlDialog(parent);

    //     dUrl->setFont(parent->systemFont);
    if (dUrl->exec() == QDialog::Rejected) {
        return;
    }

    QString urlString;

    if (dUrl->m_urllogin.length() == 0) {
        urlString = dUrl->m_urladr;
    } else {
        urlString = dUrl->m_urllogin + ":" + dUrl->m_urlpass + "@" + dUrl->m_urladr;
    }

    urlString = getAndTestUrlString(urlString);

    if (urlString.length() > 0) {
        urlString += "\n";

        QString st = textEdit->toPlainText()/*->text()*/;
        st = st + urlString;

        textEdit->setText(st);
    } else {
        MessageBox::exec(this, translate(_ERR), translate(_WRONGURLS), QMessageBox::Warning);
    }

    delete dUrl;
}


void OptionsTab::showHelp()
{
    int pos = comboAction->currentIndex();
    int origHelpID = hl01[pos];
    QString translated = (translate(origHelpID));
    label03_2->setText(translated);
}


void OptionsTab::onURLList()
{
    QString str = translate(_URLLIST);
    //     QFileDialog fd;
    //     fd = new QFileDialog(this, translate(_OPENFILE), parent->currentWorkDir, str);
    //     fd->setFont(parent->systemFont);
    //     fd->exec();
    QString name = QFileDialog::getOpenFileName(this, translate(_OPENFILE), parent->currentWorkDir, str);

    if (name == "" || name == "/" || name == "\\") {
        return;
    }

    QFile fileName(name);

    if (!fileName.open(QIODevice::ReadOnly | QIODevice::Text)) {
        return;
    }

    QString st = "";

    textEdit->clear();
    label1286->setText("");

    label1286->setText(name);

    QTextStream in(&fileName);
#if USE_QT_VERSION == 6
    in.setEncoding(QStringConverter::Utf8);
#else
    in.setCodec("UTF-8");
#endif

    while (!in.atEnd()) {
        QString line = in.readLine();
        line = getAndTestUrlString(line);

        if (line.length() > 0) {
            st = st + line + "\n";
        }
    }

    fileName.close();

    if (st.length() > 0) {
        textEdit->setText(st);
    } else {
        MessageBox::exec(this, translate(_ERR), translate(_WRONGURLS), QMessageBox::Warning);
    }
}


void OptionsTab::onSetOptions()
{
    OptionsDialog *oDia = new OptionsDialog(parent);
    //     oDia->setFont(parent->systemFont);
    oDia->exec();

    delete oDia;
}


bool OptionsTab::testIt()
{
    QString listOfUrls;
    QStringList urls;
    bool found = false;

    listOfUrls = textEdit->toPlainText();
    urls = listOfUrls.split("\n");

    for (QStringList::Iterator i = urls.begin(); i != urls.end(); i++) {
        QString result;
        result = getAndTestUrlString(*i);

        if (result.length() > 0) {
            found = true;
            break;
        }
    }

    if (found == true) {
        parent->SetProfile("CurrentUrl", listOfUrls);
    } else {
        MessageBox::exec(this, translate(_ERR), translate(_WRONGURLS), QMessageBox::Warning);
    }

    QString urlFile = label1286->text();

    if (urlFile.length() > 0) {
        parent->SetProfile("CurrentURLList", urlFile);
    }

    int action;
    action = comboAction->currentIndex();

    parent->SetProfile("CurrentAction", action);
    return (found);
}