aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-11-30 14:08:02 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-11-30 14:08:02 +0100
commitfbdaade51ceaea14998c611acf2a09d3198be640 (patch)
tree0b578c1eb01f259c482dca806bea4dc24dccc480 /src
parentAdd --session and --pick-session (diff)
downloadsmolbote-fbdaade51ceaea14998c611acf2a09d3198be640.tar.xz
pick-session: pass session data to existing instance if any
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp14
-rw-r--r--src/mainwindow/mainwindow.ui29
-rw-r--r--src/session/sessiondialog.cpp47
-rw-r--r--src/session/sessiondialog.h6
4 files changed, 78 insertions, 18 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 7cc8757..bb58782 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -237,12 +237,16 @@ int main(int argc, char **argv)
});
}
- if(pickSession) {
- auto *dlg = new SessionDialog();
- dlg->exec();
- } else {
+ {
QJsonObject sessionData;
- if(session) {
+
+ if(pickSession) {
+ auto *dlg = new SessionDialog();
+ if(const auto pick = dlg->pickSession())
+ sessionData = pick.value();
+ else
+ sessionData = Session::fromCommandLine(profile.value(), urls);
+ } else if(session) {
QFile sessionJson(session.value());
if(sessionJson.open(QIODevice::ReadOnly | QIODevice::Text)) {
sessionData = QJsonDocument::fromJson(sessionJson.readAll()).object();
diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui
index 309bfaf..19cecbb 100644
--- a/src/mainwindow/mainwindow.ui
+++ b/src/mainwindow/mainwindow.ui
@@ -85,11 +85,17 @@
</property>
</action>
<action name="actionNewWindow">
+ <property name="icon">
+ <iconset theme="window-new"/>
+ </property>
<property name="text">
<string>New &amp;Window</string>
</property>
</action>
<action name="actionAbout">
+ <property name="icon">
+ <iconset theme="help-about"/>
+ </property>
<property name="text">
<string>&amp;About</string>
</property>
@@ -100,6 +106,9 @@
</property>
</action>
<action name="actionQuit">
+ <property name="icon">
+ <iconset theme="application-exit"/>
+ </property>
<property name="text">
<string>&amp;Quit</string>
</property>
@@ -135,16 +144,25 @@
</property>
</action>
<action name="actionSavePage">
+ <property name="icon">
+ <iconset theme="document-save"/>
+ </property>
<property name="text">
<string>&amp;Save Page</string>
</property>
</action>
<action name="actionPrintPage">
+ <property name="icon">
+ <iconset theme="document-print"/>
+ </property>
<property name="text">
<string>&amp;Print Page</string>
</property>
</action>
<action name="actionPrintPageToPdf">
+ <property name="icon">
+ <iconset theme="document-print"/>
+ </property>
<property name="text">
<string>P&amp;rint to PDF</string>
</property>
@@ -155,18 +173,27 @@
</property>
</action>
<action name="actionBookmarks">
+ <property name="icon">
+ <iconset theme="bookmarks"/>
+ </property>
<property name="text">
<string>&amp;Bookmarks</string>
</property>
</action>
<action name="actionDownloads">
+ <property name="icon">
+ <iconset theme="download"/>
+ </property>
<property name="text">
<string>&amp;Downloads</string>
</property>
</action>
<action name="actionAddPlugin">
+ <property name="icon">
+ <iconset theme="plugins"/>
+ </property>
<property name="text">
- <string>Add Plugin</string>
+ <string>&amp;Add Plugin</string>
</property>
</action>
</widget>
diff --git a/src/session/sessiondialog.cpp b/src/session/sessiondialog.cpp
index 287950d..184c44d 100644
--- a/src/session/sessiondialog.cpp
+++ b/src/session/sessiondialog.cpp
@@ -28,13 +28,7 @@ SessionDialog::SessionDialog(QWidget *parent)
Q_CHECK_PTR(browser);
for(const QString &path : Util::files(browser->configuration("browser.session.path"), { "*.json" })) {
- auto *item = new QListWidgetItem(ui->listWidget);
- auto *widget = new SessionForm(path, this);
- connect(widget->ui->delete_toolButton, &QToolButton::clicked, this, [item, widget]() {
- delete item;
- delete widget;
- });
- ui->listWidget->setItemWidget(item, widget);
+ addItem(path);
}
ui->listWidget->addItem(tr("Create a new window"));
@@ -52,13 +46,12 @@ SessionDialog::SessionDialog(QWidget *parent)
connect(ui->open, &QPushButton::clicked, this, [this]() {
const QString filename = QFileDialog::getOpenFileName(this, tr("Select Session file"), QDir::homePath(), tr("JSON (*.json)"));
if(!filename.isEmpty()) {
- this->openSession(filename);
- // close the dialog window; reject so it doesn't open another session
- this->reject();
+ ui->listWidget->setCurrentItem(addItem(filename));
+ accept();
}
});
- connect(this, &SessionDialog::accepted, this, [this, browser]() {
+ accepted_connection = connect(this, &SessionDialog::accepted, this, [this, browser]() {
auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
if(currentWidget)
this->openSession(currentWidget->ui->label->text());
@@ -74,6 +67,38 @@ SessionDialog::~SessionDialog()
delete ui;
}
+std::optional<QJsonObject> SessionDialog::pickSession()
+{
+ disconnect(accepted_connection);
+
+ if(this->exec() == QDialog::Rejected) {
+ return std::nullopt;
+ }
+
+ auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
+ if(currentWidget) {
+ QFile json(currentWidget->ui->label->text());
+ if(json.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ auto doc = QJsonDocument::fromJson(json.readAll());
+ return doc.object();
+ }
+ }
+
+ return std::nullopt;
+}
+
+QListWidgetItem *SessionDialog::addItem(const QString &path)
+{
+ auto *item = new QListWidgetItem(ui->listWidget);
+ auto *widget = new SessionForm(path, this);
+ connect(widget->ui->delete_toolButton, &QToolButton::clicked, this, [item, widget]() {
+ delete item;
+ delete widget;
+ });
+ ui->listWidget->setItemWidget(item, widget);
+ return item;
+}
+
void SessionDialog::search(const QString &text)
{
for(int i = 0; i < ui->listWidget->count(); ++i) {
diff --git a/src/session/sessiondialog.h b/src/session/sessiondialog.h
index ff4d3af..9bf8a68 100644
--- a/src/session/sessiondialog.h
+++ b/src/session/sessiondialog.h
@@ -15,7 +15,7 @@ namespace Ui
{
class SessionDialog;
}
-
+class QListWidgetItem;
class SessionDialog : public QDialog
{
Q_OBJECT
@@ -24,12 +24,16 @@ public:
explicit SessionDialog(QWidget *parent = nullptr);
~SessionDialog() override;
+ std::optional<QJsonObject> pickSession();
+
private slots:
+ QListWidgetItem *addItem(const QString &path);
void search(const QString &text);
void openSession(const QString &filename);
private:
Ui::SessionDialog *ui;
+ QMetaObject::Connection accepted_connection;
};
#endif // SMOLBOTE_SESSIONDIALOG_H