Skip to content

Commit 039db57

Browse files
ShaopengLinAdam Lamar
authored and
Adam Lamar
committed
Add CheckBox in Settings for Tab Reopen Behavior
Added a checkbox in settings where user can define if they want the tab reopening feature to be active. Fix #186
1 parent 00a2be1 commit 039db57

8 files changed

+93
-9
lines changed

resources/i18n/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@
162162
"content-type-searcher-placeholder": "Filter content type",
163163
"no-details": "Introduction only",
164164
"no-pictures": "No Pictures",
165-
"no-videos": "No Videos"
165+
"no-videos": "No Videos",
166+
"open-previous-tabs-at-startup": "Open previous tabs at startup"
166167
}

resources/i18n/qqq.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
"monitor-dir-dialog-msg": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
4646
"monitor-clear-dir-dialog-title": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
4747
"monitor-clear-dir-dialog-msg": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
48-
"open-book": "\"Open\" is a imperative, not an adjective."
48+
"open-book": "\"Open\" is a imperative, not an adjective.",
49+
"open-previous-tabs-at-startup": "The tabs that were open when the user closed the application is opened again when the application is restarted."
4950
}

src/kiwixapp.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,18 @@ void KiwixApp::restoreTabs()
189189

190190
/* Restart a new session to prevent duplicate records in openURL */
191191
saveListOfOpenTabs();
192-
for (const auto &zimUrl : tabsToOpen)
192+
if (m_settingsManager.getReopenTab())
193193
{
194-
try
194+
for (const auto &zimUrl : tabsToOpen)
195195
{
196+
try
197+
{
196198
/* Throws exception if zim file cannot be found */
197199
m_library.getArchive(QUrl(zimUrl).host().split('.')[0]);
198200
openUrl(QUrl(zimUrl));
201+
}
202+
catch (std::exception &e) { /* Blank */ }
199203
}
200-
catch (std::exception &e) { /* Blank */ }
201204
}
202205
}
203206

src/settingsmanager.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ SettingsView* SettingsManager::getView()
1919
{
2020
if (m_view == nullptr) {
2121
auto view = new SettingsView();
22-
view->init(m_zoomFactor * 100, m_downloadDir, m_monitorDir, m_moveToTrash);
22+
view->init(m_zoomFactor * 100, m_downloadDir, m_monitorDir,
23+
m_moveToTrash, m_reopenTab);
2324
connect(view, &QObject::destroyed, this, [=]() { m_view = nullptr; });
2425
m_view = view;
2526
}
@@ -99,6 +100,13 @@ void SettingsManager::setMoveToTrash(bool moveToTrash)
99100
emit(moveToTrashChanged(m_moveToTrash));
100101
}
101102

103+
void SettingsManager::setReopenTab(bool reopenTab)
104+
{
105+
m_reopenTab = reopenTab;
106+
setSettings("reopenTab", m_reopenTab);
107+
emit(reopenTabChanged(reopenTab));
108+
}
109+
102110
QList<QVariant> SettingsManager::flattenPair(FilterList pairList)
103111
{
104112
QList<QVariant> res;
@@ -148,6 +156,7 @@ void SettingsManager::initSettings()
148156
m_kiwixServerIpAddress = m_settings.value("localKiwixServer/ipAddress", QString("0.0.0.0")).toString();
149157
m_monitorDir = m_settings.value("monitor/dir", QString("")).toString();
150158
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
159+
m_reopenTab = m_settings.value("reopenTab", false).toBool();
151160
QString defaultLang = QLocale::languageToString(QLocale().language()) + '|' + QLocale().name().split("_").at(0);
152161

153162
/*

src/settingsmanager.h

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SettingsManager : public QObject
2929
QString getDownloadDir() const { return m_downloadDir; }
3030
QString getMonitorDir() const { return m_monitorDir; }
3131
bool getMoveToTrash() const { return m_moveToTrash; }
32+
bool getReopenTab() const { return m_reopenTab; }
3233
FilterList getLanguageList() { return deducePair(m_langList); }
3334
FilterList getCategoryList() { return deducePair(m_categoryList); }
3435
FilterList getContentType() { return deducePair(m_contentTypeList); }
@@ -40,9 +41,11 @@ public slots:
4041
void setDownloadDir(QString downloadDir);
4142
void setMonitorDir(QString monitorDir);
4243
void setMoveToTrash(bool moveToTrash);
44+
void setReopenTab(bool reopenTab);
4345
void setLanguage(FilterList langList);
4446
void setCategory(FilterList categoryList);
4547
void setContentType(FilterList contentTypeList);
48+
4649
private:
4750
void initSettings();
4851
QList<QVariant> flattenPair(FilterList pairList);
@@ -54,6 +57,7 @@ public slots:
5457
void downloadDirChanged(QString downloadDir);
5558
void monitorDirChanged(QString monitorDir);
5659
void moveToTrashChanged(bool moveToTrash);
60+
void reopenTabChanged(bool reopenTab);
5761
void languageChanged(QList<QVariant> langList);
5862
void categoryChanged(QList<QVariant> categoryList);
5963
void contentTypeChanged(QList<QVariant> contentTypeList);
@@ -67,6 +71,7 @@ public slots:
6771
QString m_downloadDir;
6872
QString m_monitorDir;
6973
bool m_moveToTrash;
74+
bool m_reopenTab;
7075
QList<QVariant> m_langList;
7176
QList<QVariant> m_categoryList;
7277
QList<QVariant> m_contentTypeList;

src/settingsview.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SettingsView::SettingsView(QWidget *parent)
1212
ui->widget->setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/_settingsManager.css"));
1313
connect(ui->zoomPercentSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsView::setZoom);
1414
connect(ui->moveToTrashToggle, &QCheckBox::clicked, this, &SettingsView::setMoveToTrash);
15+
connect(ui->reopenTabToggle, &QCheckBox::clicked, this, &SettingsView::setReopenTab);
1516
connect(ui->browseButton, &QPushButton::clicked, this, &SettingsView::browseDownloadDir);
1617
connect(ui->resetButton, &QPushButton::clicked, this, &SettingsView::resetDownloadDir);
1718
connect(ui->monitorBrowse, &QPushButton::clicked, this, &SettingsView::browseMonitorDir);
@@ -20,6 +21,7 @@ SettingsView::SettingsView(QWidget *parent)
2021
connect(KiwixApp::instance()->getSettingsManager(), &SettingsManager::monitorDirChanged, this, &SettingsView::onMonitorDirChanged);
2122
connect(KiwixApp::instance()->getSettingsManager(), &SettingsManager::zoomChanged, this, &SettingsView::onZoomChanged);
2223
connect(KiwixApp::instance()->getSettingsManager(), &SettingsManager::moveToTrashChanged, this, &SettingsView::onMoveToTrashChanged);
24+
connect(KiwixApp::instance()->getSettingsManager(), &SettingsManager::reopenTabChanged, this, &SettingsView::onReopenTabChanged);
2325
ui->settingsLabel->setText(gt("settings"));
2426
ui->zoomPercentLabel->setText(gt("zoom-level-setting"));
2527
ui->downloadDirLabel->setText(gt("download-directory-setting"));
@@ -31,14 +33,18 @@ SettingsView::SettingsView(QWidget *parent)
3133
ui->monitorHelp->setText("<b>?</b>");
3234
ui->monitorHelp->setToolTip(gt("monitor-directory-tooltip"));
3335
ui->moveToTrashLabel->setText(gt("move-files-to-trash"));
36+
ui->reopenTabLabel->setText(gt("open-previous-tabs-at-startup"));
3437
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
38+
ui->line_5->hide();
3539
ui->moveToTrashLabel->hide();
3640
ui->moveToTrashToggle->hide();
3741
#endif
3842

3943
}
4044

41-
void SettingsView::init(int zoomPercent, const QString &downloadDir, const QString &monitorDir, const bool moveToTrash)
45+
void SettingsView::init(int zoomPercent, const QString &downloadDir,
46+
const QString &monitorDir, const bool moveToTrash,
47+
bool reopentab)
4248
{
4349
ui->zoomPercentSpinBox->setValue(zoomPercent);
4450
ui->downloadDirPath->setText(downloadDir);
@@ -47,6 +53,7 @@ void SettingsView::init(int zoomPercent, const QString &downloadDir, const QStri
4753
}
4854
ui->monitorDirPath->setText(monitorDir);
4955
ui->moveToTrashToggle->setChecked(moveToTrash);
56+
ui->reopenTabToggle->setChecked(reopentab);
5057
}
5158
bool SettingsView::confirmDialog( QString messageText, QString messageTitle)
5259
{
@@ -142,6 +149,11 @@ void SettingsView::setMoveToTrash(bool moveToTrash)
142149
KiwixApp::instance()->getSettingsManager()->setMoveToTrash(moveToTrash);
143150
}
144151

152+
void SettingsView::setReopenTab(bool reopen)
153+
{
154+
KiwixApp::instance()->getSettingsManager()->setReopenTab(reopen);
155+
}
156+
145157
void SettingsView::onDownloadDirChanged(const QString &dir)
146158
{
147159
ui->downloadDirPath->setText(dir);
@@ -167,3 +179,8 @@ void SettingsView::onMoveToTrashChanged(bool moveToTrash)
167179
{
168180
ui->moveToTrashToggle->setChecked(moveToTrash);
169181
}
182+
183+
void SettingsView::onReopenTabChanged(bool reopen)
184+
{
185+
ui->reopenTabToggle->setChecked(reopen);
186+
}

src/settingsview.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ class SettingsView : public QWidget
1111
public:
1212
SettingsView(QWidget *parent = nullptr);
1313
~SettingsView(){};
14-
void init(int zoomPercent, const QString &downloadDir, const QString &monitorDir, const bool moveToTrash);
15-
public Q_SLOTS:
14+
void init(int zoomPercent, const QString &downloadDir,
15+
const QString &monitorDir, const bool moveToTrash,
16+
bool reopentab);
17+
public Q_SLOTS:
1618
void resetDownloadDir();
1719
void browseDownloadDir();
1820
void browseMonitorDir();
1921
void clearMonitorDir();
2022
void setZoom(int zoomPercent);
2123
void setMoveToTrash(bool moveToTrash);
24+
void setReopenTab(bool reopen);
2225
void onDownloadDirChanged(const QString &dir);
2326
void onMonitorDirChanged(const QString &dir);
2427
void onZoomChanged(qreal zoomFactor);
2528
void onMoveToTrashChanged(bool moveToTrash);
29+
void onReopenTabChanged(bool reopen);
2630
private:
2731
bool confirmDialogDownloadDir(const QString& dir);
2832
bool confirmDialog(QString messageText, QString messageTitle);

ui/settings.ui

+44
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,50 @@
328328
</item>
329329
</layout>
330330
</item>
331+
<item>
332+
<widget class="Line" name="line_6">
333+
<property name="orientation">
334+
<enum>Qt::Horizontal</enum>
335+
</property>
336+
</widget>
337+
</item>
338+
<item>
339+
<layout class="QHBoxLayout" name="horizontalLayout_9">
340+
<property name="topMargin">
341+
<number>0</number>
342+
</property>
343+
<property name="rightMargin">
344+
<number>0</number>
345+
</property>
346+
<item>
347+
<widget class="QLabel" name="reopenTabLabel">
348+
<property name="text">
349+
<string>Re-open closed tabs</string>
350+
</property>
351+
</widget>
352+
</item>
353+
<item>
354+
<spacer name="horizontalSpacer_5">
355+
<property name="orientation">
356+
<enum>Qt::Horizontal</enum>
357+
</property>
358+
<property name="sizeHint" stdset="0">
359+
<size>
360+
<width>40</width>
361+
<height>20</height>
362+
</size>
363+
</property>
364+
</spacer>
365+
</item>
366+
<item>
367+
<widget class="QCheckBox" name="reopenTabToggle">
368+
<property name="text">
369+
<string/>
370+
</property>
371+
</widget>
372+
</item>
373+
</layout>
374+
</item>
331375
<item>
332376
<spacer name="verticalSpacer">
333377
<property name="orientation">

0 commit comments

Comments
 (0)