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,84 +137,80 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths, ...@@ -137,84 +137,80 @@ SessionRestoreDialog::SessionRestoreDialog(const QStringList &sessionFilePaths,
hLayout->addSpacing(KDialog::spacingHint()); hLayout->addSpacing(KDialog::spacingHint());
hLayout->addWidget(messageLabel, 5); hLayout->addWidget(messageLabel, 5);
QTreeWidget *treeWidget = 0; Q_ASSERT(!sessionFilePaths.isEmpty());
if (!sessionFilePaths.isEmpty()) { m_treeWidget = new QTreeWidget(mainWidget);
treeWidget = new QTreeWidget(mainWidget); m_treeWidget->setHeader(0);
treeWidget->setHeader(0); m_treeWidget->setHeaderHidden(true);
treeWidget->setHeaderHidden(true); m_treeWidget->setToolTip(i18nc("@tooltip:session list", "Uncheck the sessions you do not want to be restored"));
treeWidget->setToolTip(i18nc("@tooltip:session list", "Uncheck the sessions you do not want to be restored"));
QStyleOptionViewItem styleOption;
QStyleOptionViewItem styleOption; styleOption.initFrom(m_treeWidget);
styleOption.initFrom(treeWidget); QFontMetrics fm(styleOption.font);
QFontMetrics fm(styleOption.font); int w = m_treeWidget->width();
int w = treeWidget->width(); const QRect desktop = QApplication::desktop()->screenGeometry(this);
const QRect desktop = QApplication::desktop()->screenGeometry(this);
// Collect info from the sessions to restore
// Collect info from the sessions to restore Q_FOREACH (const QString &sessionFile, sessionFilePaths) {
Q_FOREACH (const QString &sessionFile, sessionFilePaths) { qDebug() << sessionFile;
qDebug() << sessionFile; QTreeWidgetItem *windowItem = 0;
QTreeWidgetItem *windowItem = 0; KConfig config(sessionFile, KConfig::SimpleConfig);
KConfig config(sessionFile, KConfig::SimpleConfig); const QList<KConfigGroup> groups = windowConfigGroups(config);
const QList<KConfigGroup> groups = windowConfigGroups(config); Q_FOREACH (const KConfigGroup &group, groups) {
Q_FOREACH (const KConfigGroup &group, groups) { // To avoid a recursive search, let's do linear search on Foo_CurrentHistoryItem=1
// To avoid a recursive search, let's do linear search on Foo_CurrentHistoryItem=1 Q_FOREACH (const QString &key, group.keyList()) {
Q_FOREACH (const QString &key, group.keyList()) { if (key.endsWith(QLatin1String("_CurrentHistoryItem"))) {
if (key.endsWith(QLatin1String("_CurrentHistoryItem"))) { const QString viewId = key.left(key.length() - qstrlen("_CurrentHistoryItem"));
const QString viewId = key.left(key.length() - qstrlen("_CurrentHistoryItem")); const QString historyIndex = group.readEntry(key, QString());
const QString historyIndex = group.readEntry(key, QString()); const QString prefix = "HistoryItem" + viewId + '_' + historyIndex;
const QString prefix = "HistoryItem" + viewId + '_' + historyIndex; // Ignore the sidebar views
// Ignore the sidebar views if (group.readEntry(prefix + "StrServiceName", QString()).startsWith(QLatin1String("konq_sidebar"))) {
if (group.readEntry(prefix + "StrServiceName", QString()).startsWith(QLatin1String("konq_sidebar"))) { continue;
continue; }
} const QString url = group.readEntry(prefix + "Url", QString());
const QString url = group.readEntry(prefix + "Url", QString()); const QString title = group.readEntry(prefix + "Title", QString());
const QString title = group.readEntry(prefix + "Title", QString()); qDebug() << viewId << url << title;
qDebug() << viewId << url << title; const QString displayText = (title.trimmed().isEmpty() ? url : title);
const QString displayText = (title.trimmed().isEmpty() ? url : title); if (!displayText.isEmpty()) {
if (!displayText.isEmpty()) { if (!windowItem) {
if (!windowItem) { windowItem = new QTreeWidgetItem(m_treeWidget);
windowItem = new QTreeWidgetItem(treeWidget); const int index = sessionFilePaths.indexOf(sessionFile) + 1;
const int index = sessionFilePaths.indexOf(sessionFile) + 1; windowItem->setText(0, i18nc("@item:treewidget", "Window %1", index));
windowItem->setText(0, i18nc("@item:treewidget", "Window %1", index)); windowItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
windowItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); windowItem->setCheckState(0, Qt::Checked);
windowItem->setCheckState(0, Qt::Checked); windowItem->setExpanded(true);
windowItem->setExpanded(true);
}
QTreeWidgetItem *item = new QTreeWidgetItem(windowItem);
item->setText(0, displayText);
item->setData(0, Qt::UserRole, viewIdFor(sessionFile, viewId));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Checked);
w = qMax(w, fm.width(displayText));
m_sessionItemsCount++;
} }
QTreeWidgetItem *item = new QTreeWidgetItem(windowItem);
item->setText(0, displayText);
item->setData(0, Qt::UserRole, viewIdFor(sessionFile, viewId));
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Checked);
w = qMax(w, fm.width(displayText));
m_sessionItemsCount++;
} }
} }
} }
if (windowItem) {
m_checkedSessionItems.insert(windowItem, windowItem->childCount());
}
} }
const int borderWidth = treeWidget->width() - treeWidget->viewport()->width() + treeWidget->verticalScrollBar()->height(); if (windowItem) {
w += borderWidth; m_checkedSessionItems.insert(windowItem, windowItem->childCount());
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);
messageLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
} }
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);
}
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 // Do not connect the itemChanged signal until after the treewidget
// is completely populated to prevent the firing of the itemChanged // is completely populated to prevent the firing of the itemChanged
// signal while in the process of adding the original session items. // signal while in the process of adding the original session items.
if (treeWidget && treeWidget->topLevelItemCount() > 0) { connect(m_treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)),
connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
this, SLOT(slotItemChanged(QTreeWidgetItem*,int)));
}
QCheckBox *checkbox = new QCheckBox(i18n("Do not ask again"), mainWidget); QCheckBox *checkbox = new QCheckBox(i18n("Do not ask again"), mainWidget);
connect(checkbox, &QCheckBox::clicked, this, &SessionRestoreDialog::slotClicked); connect(checkbox, &QCheckBox::clicked, this, &SessionRestoreDialog::slotClicked);
...@@ -227,6 +223,11 @@ SessionRestoreDialog::~SessionRestoreDialog() ...@@ -227,6 +223,11 @@ SessionRestoreDialog::~SessionRestoreDialog()
{ {
} }
bool SessionRestoreDialog::isEmpty() const
{
return m_treeWidget->topLevelItemCount() == 0;
}
QStringList SessionRestoreDialog::discardedSessionList() const QStringList SessionRestoreDialog::discardedSessionList() const
{ {
return m_discardedSessionList; return m_discardedSessionList;
...@@ -651,10 +652,14 @@ bool KonqSessionManager::askUserToRestoreAutosavedAbandonedSessions() ...@@ -651,10 +652,14 @@ bool KonqSessionManager::askUserToRestoreAutosavedAbandonedSessions()
if (SessionRestoreDialog::shouldBeShown(dontAskAgainName, &result)) { if (SessionRestoreDialog::shouldBeShown(dontAskAgainName, &result)) {
SessionRestoreDialog *restoreDlg = new SessionRestoreDialog(sessionFilePaths); SessionRestoreDialog *restoreDlg = new SessionRestoreDialog(sessionFilePaths);
result = restoreDlg->exec(); if (restoreDlg->isEmpty()) {
discardedSessionList = restoreDlg->discardedSessionList(); result = KDialog::No;
if (restoreDlg->isDontShowChecked()) { } else {
SessionRestoreDialog::saveDontShow(dontAskAgainName, result); result = restoreDlg->exec();
discardedSessionList = restoreDlg->discardedSessionList();
if (restoreDlg->isDontShowChecked()) {
SessionRestoreDialog::saveDontShow(dontAskAgainName, result);
}
} }
delete restoreDlg; delete restoreDlg;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <konqprivate_export.h> #include <konqprivate_export.h>
class KonqMainWindow; class KonqMainWindow;
class QTreeWidget;
class QTreeWidgetItem; class QTreeWidgetItem;
class QSessionManager; class QSessionManager;
...@@ -41,6 +42,8 @@ public: ...@@ -41,6 +42,8 @@ public:
explicit SessionRestoreDialog(const QStringList &sessionFilePaths, QWidget *parent = Q_NULLPTR); explicit SessionRestoreDialog(const QStringList &sessionFilePaths, QWidget *parent = Q_NULLPTR);
virtual ~SessionRestoreDialog(); virtual ~SessionRestoreDialog();
bool isEmpty() const;
/** /**
* Returns the list of session discarded/unselected by the user. * Returns the list of session discarded/unselected by the user.
*/ */
...@@ -76,6 +79,7 @@ private Q_SLOTS: ...@@ -76,6 +79,7 @@ private Q_SLOTS:
void slotItemChanged(QTreeWidgetItem *, int); void slotItemChanged(QTreeWidgetItem *, int);
private: private:
QTreeWidget *m_treeWidget;
QStringList m_discardedSessionList; QStringList m_discardedSessionList;
QHash<QTreeWidgetItem *, int> m_checkedSessionItems; QHash<QTreeWidgetItem *, int> m_checkedSessionItems;
int m_sessionItemsCount; 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