Commit 1d35838c authored by David Faure's avatar David Faure

Don't offer to restore an empty list of windows

(happens with an autosave file that says "Number of Windows = 0" for some reason)
parent e025cb34
......@@ -137,17 +137,16 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths,
hLayout->addSpacing(KDialog::spacingHint());
hLayout->addWidget(messageLabel, 5);
QTreeWidget *treeWidget = 0;
if (!sessionFilePaths.isEmpty()) {
treeWidget = new QTreeWidget(mainWidget);
treeWidget->setHeader(0);
treeWidget->setHeaderHidden(true);
treeWidget->setToolTip(i18nc("@tooltip:session list", "Uncheck the sessions you do not want to be restored"));
Q_ASSERT(!sessionFilePaths.isEmpty());
m_treeWidget = new QTreeWidget(mainWidget);
m_treeWidget->setHeader(0);
m_treeWidget->setHeaderHidden(true);
m_treeWidget->setToolTip(i18nc("@tooltip:session list", "Uncheck the sessions you do not want to be restored"));
QStyleOptionViewItem styleOption;
styleOption.initFrom(treeWidget);
styleOption.initFrom(m_treeWidget);
QFontMetrics fm(styleOption.font);
int w = treeWidget->width();
int w = m_treeWidget->width();
const QRect desktop = QApplication::desktop()->screenGeometry(this);
// Collect info from the sessions to restore
......@@ -173,7 +172,7 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths,
const QString displayText = (title.trimmed().isEmpty() ? url : title);
if (!displayText.isEmpty()) {
if (!windowItem) {
windowItem = new QTreeWidgetItem(treeWidget);
windowItem = new QTreeWidgetItem(m_treeWidget);
const int index = sessionFilePaths.indexOf(sessionFile) + 1;
windowItem->setText(0, i18nc("@item:treewidget", "Window %1", index));
windowItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
......@@ -197,24 +196,21 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths,
}
}
const int borderWidth = treeWidget->width() - treeWidget->viewport()->width() + treeWidget->verticalScrollBar()->height();
const int borderWidth = m_treeWidget->width() - m_treeWidget->viewport()->width() + m_treeWidget->verticalScrollBar()->height();
w += borderWidth;
if (w > desktop.width() * 0.85) { // limit treeWidget size to 85% of screen width
w = qRound(desktop.width() * 0.85);
}
treeWidget->setMinimumWidth(w);
mainLayout->addWidget(treeWidget, 50);
treeWidget->setSelectionMode(QTreeWidget::NoSelection);
m_treeWidget->setMinimumWidth(w);
mainLayout->addWidget(m_treeWidget, 50);
m_treeWidget->setSelectionMode(QTreeWidget::NoSelection);
messageLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
}
// Do not connect the itemChanged signal until after the treewidget
// is completely populated to prevent the firing of the itemChanged
// signal while in the process of adding the original session items.
if (treeWidget && treeWidget->topLevelItemCount() > 0) {
connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
connect(m_treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
}
QCheckBox *checkbox = new QCheckBox(i18n("Do not ask again"), mainWidget);
connect(checkbox, &QCheckBox::clicked, this, &SessionRestoreDialog::slotClicked);
......@@ -227,6 +223,11 @@ SessionRestoreDialog::~SessionRestoreDialog()
{
}
bool SessionRestoreDialog::isEmpty() const
{
return m_treeWidget->topLevelItemCount() == 0;
}
QStringList SessionRestoreDialog::discardedSessionList() const
{
return m_discardedSessionList;
......@@ -651,11 +652,15 @@ bool KonqSessionManager::askUserToRestoreAutosavedAbandonedSessions()
if (SessionRestoreDialog::shouldBeShown(dontAskAgainName, &result)) {
SessionRestoreDialog *restoreDlg = new SessionRestoreDialog(sessionFilePaths);
if (restoreDlg->isEmpty()) {
result = KDialog::No;
} else {
result = restoreDlg->exec();
discardedSessionList = restoreDlg->discardedSessionList();
if (restoreDlg->isDontShowChecked()) {
SessionRestoreDialog::saveDontShow(dontAskAgainName, result);
}
}
delete restoreDlg;
}
......
......@@ -31,6 +31,7 @@
#include <konqprivate_export.h>
class KonqMainWindow;
class QTreeWidget;
class QTreeWidgetItem;
class QSessionManager;
......@@ -41,6 +42,8 @@ public:
explicit SessionRestoreDialog(const QStringList &sessionFilePaths, QWidget *parent = Q_NULLPTR);
virtual ~SessionRestoreDialog();
bool isEmpty() const;
/**
* Returns the list of session discarded/unselected by the user.
*/
......@@ -76,6 +79,7 @@ private Q_SLOTS:
void slotItemChanged(QTreeWidgetItem *, int);
private:
QTreeWidget *m_treeWidget;
QStringList m_discardedSessionList;
QHash<QTreeWidgetItem *, int> m_checkedSessionItems;
int m_sessionItemsCount;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment