Show dialog to ask when closing when more than tab open

Summary:
The checkbox is checked and says "Warn me on closing more than one tab",
for that reason we can't use the default KMessageBox::questionYesNo since
there the checkbox is always not checked and it's when checked that you enable it

Inspired by code from torham zed torhamzed@yahoo.com at review request 126406

Reviewers: #okular, #kde_applications

Subscribers: alexeymin, ngraham, colomar, rkflx, #okular

Tags: #okular

Differential Revision: https://phabricator.kde.org/D7714
remotes/origin/Applications/17.12
Albert Astals Cid 9 years ago
parent a57ffdbd95
commit 95a32d7730
  1. 3
      autotests/mainshelltest.cpp
  2. 33
      shell/shell.cpp

@ -123,10 +123,11 @@ void MainShellTest::initTestCase()
const QString serviceName = QStringLiteral("org.kde.okular-")+ myPid;
QVERIFY( bus->registerService(serviceName) == QDBusConnectionInterface::ServiceRegistered );
// Tell the presentationWidget to not be annoying
// Tell the presentationWidget and queryClose to not be annoying
KSharedConfigPtr c = KSharedConfig::openConfig();
KConfigGroup cg = c->group("Notification Messages");
cg.writeEntry("presentationInfo", false);
cg.writeEntry("ShowTabWarning", false);
}
void MainShellTest::cleanupTestCase()

@ -544,6 +544,39 @@ QSize Shell::sizeHint() const
bool Shell::queryClose()
{
if (m_tabs.count() > 1)
{
const QString dontAskAgainName = "ShowTabWarning";
KMessageBox::ButtonCode dummy;
if (shouldBeShownYesNo(dontAskAgainName, dummy))
{
QDialog *dialog = new QDialog(this);
dialog->setWindowTitle(i18n("Confirm Close"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), KGuiItem(i18n("Close Tabs"), "tab-close"));
KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), KStandardGuiItem::cancel());
bool checkboxResult = true;
const int result = KMessageBox::createKMessageBox(dialog, buttonBox, QMessageBox::Question,
i18n("You have about to close %1 tabs. Are you sure you want to continue?", m_tabs.count()), QStringList(),
i18n("Warn me when I attempt to close multiple tabs"),
&checkboxResult, KMessageBox::Notify);
if (!checkboxResult)
{
saveDontShowAgainYesNo(dontAskAgainName, dummy);
}
if (result != QDialogButtonBox::Yes)
{
return false;
}
}
}
for( int i = 0; i < m_tabs.size(); ++i )
{
KParts::ReadWritePart* const part = m_tabs[i].part;

Loading…
Cancel
Save