diff --git a/autotests/ktoolbar_unittest.cpp b/autotests/ktoolbar_unittest.cpp index 09b96dc..30ed19a 100644 --- a/autotests/ktoolbar_unittest.cpp +++ b/autotests/ktoolbar_unittest.cpp @@ -1,671 +1,671 @@ /* This file is part of the KDE libraries Copyright (c) 2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "testxmlguiwindow.h" #include "testguiclient.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include // We use the data types below in a QVariant, so Q_DECLARE_METATYPE is needed for them. Q_DECLARE_METATYPE(Qt::MouseButton) Q_DECLARE_METATYPE(Qt::MouseButtons) Q_DECLARE_METATYPE(Qt::KeyboardModifiers) // Ensure everything uses test paths, including stuff run before main, such as the KdePlatformThemePlugin void enableTestMode() { QStandardPaths::enableTestMode(true); } Q_CONSTRUCTOR_FUNCTION(enableTestMode) class tst_KToolBar : public QObject { Q_OBJECT public Q_SLOTS: void initTestCase(); void cleanupTestCase(); void init(); void cleanup(); private Q_SLOTS: void ktoolbar(); void testIconSizeNoXmlGui_data(); void testIconSizeNoXmlGui(); void testIconSizeXmlGui_data(); void testIconSizeXmlGui(); void testToolButtonStyleNoXmlGui_data(); void testToolButtonStyleNoXmlGui(); void testToolButtonStyleXmlGui_data(); void testToolButtonStyleXmlGui(); void testToolBarPosition(); void testXmlGuiSwitching(); void testKAuthorizedDisableToggleAction(); Q_SIGNALS: void signalAppearanceChanged(); protected: bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; private: void changeGlobalIconSizeSetting(int, int); void deleteGlobalIconSizeSetting(); void changeGlobalToolButtonStyleSetting(const QString &, const QString &); void deleteGlobalToolButtonStyleSetting(); QByteArray m_xml; bool m_showWasCalled; }; QTEST_MAIN(tst_KToolBar) static void copy_dir(const QString &from, const QDir &to) { QDir src = QDir(from); QDir dest = QDir(to.filePath(src.dirName())); to.mkpath(src.dirName()); foreach (const QFileInfo &fileInfo, src.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) { if (fileInfo.isDir()) { copy_dir(fileInfo.filePath(), dest); } else { QFile::copy(fileInfo.filePath(), dest.filePath(fileInfo.fileName())); } } } // This will be called before the first test function is executed. // It is only called once. void tst_KToolBar::initTestCase() { // start with a clean place to put data QDir testDataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); QVERIFY(testDataDir.absolutePath().contains(QStringLiteral("qttest"))); testDataDir.removeRecursively(); testDataDir.mkpath(QStringLiteral(".")); // setup action restriction so we can test whether this actually disables some functionality KConfigGroup actionRestrictions(KSharedConfig::openConfig(), "KDE Action Restrictions"); actionRestrictions.writeEntry("action/options_show_toolbar", false); // copy a minimal icon theme to where KIconTheme will find it, in case oxygen-icons is not // installed copy_dir(QFINDTESTDATA("icons"), testDataDir); m_xml = "\n" - "\n" + "\n" "\n" "\n" "\n" "\n" " \n" "\n" "\n" " \n" "\n" "\n" " \n" "\n" "\n" "\n" "\n" " \n" "\n" "\n" " \n" "\n" "\n"; qRegisterMetaType("Qt::MouseButtons"); qRegisterMetaType("Qt::KeyboardModifiers"); } // This will be called after the last test function is executed. // It is only called once. void tst_KToolBar::cleanupTestCase() { QDir testDataDir = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); QDir testIconsDir = QDir(testDataDir.absoluteFilePath(QStringLiteral("icons"))); QVERIFY(testIconsDir.absolutePath().contains(QStringLiteral("qttest"))); testIconsDir.removeRecursively(); } // This will be called before each test function is executed. void tst_KToolBar::init() { } // This will be called after every test function. void tst_KToolBar::cleanup() { QFile::remove(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + QStringLiteral("tst_KToolBar")); deleteGlobalIconSizeSetting(); deleteGlobalToolButtonStyleSetting(); } void tst_KToolBar::ktoolbar() { KMainWindow kmw; // Creating a KToolBar directly KToolBar bar(&kmw); QCOMPARE(bar.mainWindow(), &kmw); // Asking KMainWindow for a KToolBar (more common) KToolBar *mainToolBar = kmw.toolBar(QStringLiteral("mainToolBar")); QCOMPARE(mainToolBar->mainWindow(), &kmw); } Q_DECLARE_METATYPE(KConfigGroup) void tst_KToolBar::testIconSizeNoXmlGui_data() { QTest::addColumn("iconSize"); QTest::newRow("16") << 16; QTest::newRow("22") << 22; QTest::newRow("32") << 32; QTest::newRow("64") << 64; } void tst_KToolBar::testIconSizeNoXmlGui() { QFETCH(int, iconSize); KConfig config(QStringLiteral("tst_KToolBar")); KConfigGroup group(&config, "group"); { KMainWindow kmw; KToolBar *mainToolBar = kmw.toolBar(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBar(QStringLiteral("otherToolBar")); // Default settings (applied by applyAppearanceSettings) QCOMPARE(mainToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::MainToolbar)); QCOMPARE(otherToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); // check the actual values - update this if kicontheme's defaults are changed QCOMPARE(KIconLoader::global()->currentSize(KIconLoader::MainToolbar), 22); QCOMPARE(KIconLoader::global()->currentSize(KIconLoader::Toolbar), 22); // Changing settings for a given toolbar, as user mainToolBar->setIconDimensions(iconSize); otherToolBar->setIconDimensions(iconSize); // Save settings kmw.saveMainWindowSettings(group); // was it the default value? if (iconSize == KIconLoader::global()->currentSize(KIconLoader::MainToolbar)) { QCOMPARE(group.groupList().count(), 0); // nothing to save QVERIFY(!group.group("Toolbar mainToolBar").hasKey("IconSize")); } else { QCOMPARE(group.groupList().count(), 2); // two subgroups (one for each toolbar) QVERIFY(group.group("Toolbar mainToolBar").hasKey("IconSize")); } } { // Recreate, load, compare. KMainWindow kmw; KToolBar *mainToolBar = kmw.toolBar(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBar(QStringLiteral("otherToolBar")); KToolBar *cleanToolBar = kmw.toolBar(QStringLiteral("cleanToolBar")); QCOMPARE(mainToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::MainToolbar)); QCOMPARE(otherToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); QCOMPARE(cleanToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); kmw.applyMainWindowSettings(group); QCOMPARE(mainToolBar->iconSize().width(), iconSize); QCOMPARE(otherToolBar->iconSize().width(), iconSize); QCOMPARE(cleanToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); // unchanged const bool mainToolBarWasUsingDefaultSize = iconSize == KIconLoader::global()->currentSize(KIconLoader::MainToolbar); const bool otherToolBarWasUsingDefaultSize = iconSize == KIconLoader::global()->currentSize(KIconLoader::Toolbar); // Now emulate a change of the kde-global setting (#168480#c12) changeGlobalIconSizeSetting(32, 33); QCOMPARE(KIconLoader::global()->currentSize(KIconLoader::MainToolbar), 32); QCOMPARE(KIconLoader::global()->currentSize(KIconLoader::Toolbar), 33); if (mainToolBarWasUsingDefaultSize) { QCOMPARE(mainToolBar->iconSize().width(), 32); } else { // the user chose a specific size for the toolbar, so the new global size isn't used QCOMPARE(mainToolBar->iconSize().width(), iconSize); } if (otherToolBarWasUsingDefaultSize) { QCOMPARE(otherToolBar->iconSize().width(), 33); } else { // the user chose a specific size for the toolbar, so the new global size isn't used QCOMPARE(otherToolBar->iconSize().width(), iconSize); } QCOMPARE(cleanToolBar->iconSize().width(), 33); } } void tst_KToolBar::testIconSizeXmlGui_data() { QTest::addColumn("iconSize"); // set by user and saved to KConfig QTest::addColumn("expectedSizeMainToolbar"); // ... after kde-global is changed to 25 QTest::addColumn("expectedSizeOtherToolbar"); // ... after kde-global is changed to 16 QTest::addColumn("expectedSizeCleanToolbar"); // ... after kde-global is changed to 16 QTest::addColumn("expectedSizeBigToolbar"); // ... after kde-global is changed to 16 // When the user chose a specific size for the toolbar (!= its default size), the new kde-global size isn't applied to that toolbar. // So, only in case the toolbar was at iconSize already, and there was no setting in xml, we end up with kdeGlobal being used: const int kdeGlobalMain = 25; const int kdeGlobalOther = 16; QTest::newRow("16") << 16 << 16 << 16 << kdeGlobalOther << 16; QTest::newRow("22") << 22 << kdeGlobalMain << kdeGlobalOther << kdeGlobalOther << 22; QTest::newRow("32") << 32 << 32 << 32 << kdeGlobalOther << 32; QTest::newRow("64") << 64 << 64 << 64 << kdeGlobalOther << 64; } void tst_KToolBar::testIconSizeXmlGui() { QFETCH(int, iconSize); QFETCH(int, expectedSizeMainToolbar); QFETCH(int, expectedSizeOtherToolbar); QFETCH(int, expectedSizeCleanToolbar); QFETCH(int, expectedSizeBigToolbar); KConfig config(QStringLiteral("tst_KToolBar")); KConfigGroup group(&config, "group"); { TestXmlGuiWindow kmw(m_xml); kmw.createActions(QStringList() << QStringLiteral("go_up")); kmw.createGUI(); KToolBar *mainToolBar = kmw.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBarByName(QStringLiteral("otherToolBar")); KToolBar *cleanToolBar = kmw.toolBarByName(QStringLiteral("cleanToolBar")); KToolBar *bigToolBar = kmw.toolBarByName(QStringLiteral("bigToolBar")); KToolBar *bigUnchangedToolBar = kmw.toolBarByName(QStringLiteral("bigUnchangedToolBar")); // Default settings (applied by applyAppearanceSettings) QCOMPARE(mainToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::MainToolbar)); QCOMPARE(otherToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); // check the actual values - update this if kicontheme's defaults are changed QCOMPARE(mainToolBar->iconSize().width(), 22); QCOMPARE(otherToolBar->iconSize().width(), 22); QCOMPARE(cleanToolBar->iconSize().width(), 22); QCOMPARE(bigToolBar->iconSize().width(), 32); QCOMPARE(bigUnchangedToolBar->iconSize().width(), 32); // Changing settings for a given toolbar, as user (to test the initial report in #168480) mainToolBar->setIconDimensions(iconSize); otherToolBar->setIconDimensions(iconSize); bigToolBar->setIconDimensions(iconSize); // Save settings kmw.saveMainWindowSettings(group); // was it the default size? (for the main toolbar, we only check that one) const bool usingDefaultSize = iconSize == KIconLoader::global()->currentSize(KIconLoader::MainToolbar); if (usingDefaultSize) { QVERIFY(!group.groupList().contains(QStringLiteral("Toolbar mainToolBar"))); QVERIFY(!group.group("Toolbar mainToolBar").hasKey("IconSize")); } else { QVERIFY(group.group("Toolbar mainToolBar").hasKey("IconSize")); } // Now emulate a change of the kde-global setting (#168480#c12) changeGlobalIconSizeSetting(25, 16); QCOMPARE(mainToolBar->iconSize().width(), expectedSizeMainToolbar); QCOMPARE(otherToolBar->iconSize().width(), expectedSizeOtherToolbar); QCOMPARE(cleanToolBar->iconSize().width(), expectedSizeCleanToolbar); QCOMPARE(bigToolBar->iconSize().width(), expectedSizeBigToolbar); // The big unchanged toolbar should be, well, unchanged; AppXml has priority over KDE_Default. QCOMPARE(bigUnchangedToolBar->iconSize().width(), 32); } } void tst_KToolBar::changeGlobalIconSizeSetting(int mainToolbarIconSize, int iconSize) { // We could use KConfig::Normal|KConfig::Global here, to write to kdeglobals like kcmstyle does, // but we don't need to. Writing to the app's config file works too. KConfigGroup mglobals(KSharedConfig::openConfig(), "MainToolbarIcons"); mglobals.writeEntry("Size", mainToolbarIconSize); KConfigGroup globals(KSharedConfig::openConfig(), "ToolbarIcons"); //globals.writeEntry("Size", iconSize, KConfig::Normal|KConfig::Global); globals.writeEntry("Size", iconSize); KSharedConfig::openConfig()->sync(); QSignalSpy spy(KIconLoader::global(), SIGNAL(iconChanged(int))); KIconLoader::global()->emitChange(KIconLoader::Desktop); spy.wait(200); } void tst_KToolBar::deleteGlobalIconSizeSetting() { KConfigGroup mglobals(KSharedConfig::openConfig(), "MainToolbarIcons"); mglobals.deleteEntry("Size"); KConfigGroup globals(KSharedConfig::openConfig(), "ToolbarIcons"); globals.deleteEntry("Size"); KSharedConfig::openConfig()->sync(); QSignalSpy spy(KIconLoader::global(), SIGNAL(iconChanged(int))); KIconLoader::global()->emitChange(KIconLoader::Desktop); spy.wait(200); } Q_DECLARE_METATYPE(Qt::ToolButtonStyle) void tst_KToolBar::testToolButtonStyleNoXmlGui_data() { QTest::addColumn("toolButtonStyle"); QTest::newRow("Qt::ToolButtonIconOnly") << Qt::ToolButtonIconOnly; QTest::newRow("Qt::ToolButtonTextOnly") << Qt::ToolButtonTextOnly; QTest::newRow("Qt::ToolButtonTextBesideIcon") << Qt::ToolButtonTextBesideIcon; QTest::newRow("Qt::ToolButtonTextUnderIcon") << Qt::ToolButtonTextUnderIcon; } void tst_KToolBar::testToolButtonStyleNoXmlGui() { QFETCH(Qt::ToolButtonStyle, toolButtonStyle); const Qt::ToolButtonStyle mainToolBarDefaultStyle = Qt::ToolButtonTextBesideIcon; // was TextUnderIcon before KDE-4.4.0 const bool selectedDefaultForMainToolbar = toolButtonStyle == mainToolBarDefaultStyle; const bool selectedDefaultForOtherToolbar = toolButtonStyle == Qt::ToolButtonTextBesideIcon; KConfig config(QStringLiteral("tst_KToolBar")); KConfigGroup group(&config, "group"); { KMainWindow kmw; KToolBar *mainToolBar = kmw.toolBar(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBar(QStringLiteral("otherToolBar")); // Default settings (applied by applyAppearanceSettings) QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)mainToolBarDefaultStyle); QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)Qt::ToolButtonTextBesideIcon); // see r883541 QCOMPARE(kmw.toolBarArea(mainToolBar), Qt::TopToolBarArea); // Changing settings for a given toolbar, as user mainToolBar->setToolButtonStyle(toolButtonStyle); otherToolBar->setToolButtonStyle(toolButtonStyle); // Save settings kmw.saveMainWindowSettings(group); if (selectedDefaultForMainToolbar) { QCOMPARE(group.groupList().count(), 0); // nothing to save QVERIFY(!group.group("Toolbar mainToolBar").hasKey("ToolButtonStyle")); } else { QCOMPARE(group.groupList().count(), 2); // two subgroups (one for each toolbar) QVERIFY(group.group("Toolbar mainToolBar").hasKey("ToolButtonStyle")); } } { // Recreate, load, compare. KMainWindow kmw; KToolBar *mainToolBar = kmw.toolBar(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBar(QStringLiteral("otherToolBar")); QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)mainToolBarDefaultStyle); kmw.applyMainWindowSettings(group); QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)toolButtonStyle); QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)toolButtonStyle); // Now change KDE-global setting changeGlobalToolButtonStyleSetting(QStringLiteral("IconOnly"), QStringLiteral("TextOnly")); if (selectedDefaultForMainToolbar) { QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)Qt::ToolButtonIconOnly); } else { QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)toolButtonStyle); } if (selectedDefaultForOtherToolbar) { QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)Qt::ToolButtonTextOnly); } else { QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)toolButtonStyle); } } } void tst_KToolBar::testToolButtonStyleXmlGui_data() { QTest::addColumn("toolButtonStyle"); // Expected style after KDE-global is changed to main=IconOnly/other=TextOnly QTest::addColumn("expectedStyleMainToolbar"); QTest::addColumn("expectedStyleOtherToolbar"); // xml says text-under-icons, user-selected should always win QTest::addColumn("expectedStyleCleanToolbar"); // should always follow kde-global -> always textonly. QTest::newRow("Qt::ToolButtonTextUnderIcon") << Qt::ToolButtonTextUnderIcon << Qt::ToolButtonTextUnderIcon << Qt::ToolButtonTextUnderIcon << Qt::ToolButtonTextOnly; QTest::newRow("Qt::ToolButtonTextBesideIcon") << Qt::ToolButtonTextBesideIcon << Qt::ToolButtonIconOnly /* was default -> using kde global */ << Qt::ToolButtonTextBesideIcon << Qt::ToolButtonTextOnly; QTest::newRow("Qt::ToolButtonIconOnly") << Qt::ToolButtonIconOnly << Qt::ToolButtonIconOnly << Qt::ToolButtonIconOnly << Qt::ToolButtonTextOnly; QTest::newRow("Qt::ToolButtonTextOnly") << Qt::ToolButtonTextOnly << Qt::ToolButtonTextOnly << Qt::ToolButtonTextOnly << Qt::ToolButtonTextOnly; } void tst_KToolBar::testToolButtonStyleXmlGui() { QFETCH(Qt::ToolButtonStyle, toolButtonStyle); QFETCH(Qt::ToolButtonStyle, expectedStyleMainToolbar); QFETCH(Qt::ToolButtonStyle, expectedStyleOtherToolbar); QFETCH(Qt::ToolButtonStyle, expectedStyleCleanToolbar); const Qt::ToolButtonStyle mainToolBarDefaultStyle = Qt::ToolButtonTextBesideIcon; // was TextUnderIcon before KDE-4.4.0 KConfig config(QStringLiteral("tst_KToolBar")); KConfigGroup group(&config, "group"); { TestXmlGuiWindow kmw(m_xml); kmw.createActions(QStringList() << QStringLiteral("go_up")); kmw.createGUI(); KToolBar *mainToolBar = kmw.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBarByName(QStringLiteral("otherToolBar")); KToolBar *cleanToolBar = kmw.toolBarByName(QStringLiteral("cleanToolBar")); QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)mainToolBarDefaultStyle); QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)Qt::ToolButtonTextUnderIcon); // from xml QCOMPARE((int)cleanToolBar->toolButtonStyle(), (int)Qt::ToolButtonTextBesideIcon); // Changing settings for a given toolbar, as user mainToolBar->setToolButtonStyle(toolButtonStyle); otherToolBar->setToolButtonStyle(toolButtonStyle); // Save settings kmw.saveMainWindowSettings(group); // Now change KDE-global setting changeGlobalToolButtonStyleSetting(QStringLiteral("IconOnly"), QStringLiteral("TextOnly")); QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)expectedStyleMainToolbar); QCOMPARE((int)otherToolBar->toolButtonStyle(), (int)expectedStyleOtherToolbar); QCOMPARE((int)cleanToolBar->toolButtonStyle(), (int)expectedStyleCleanToolbar); } } void tst_KToolBar::changeGlobalToolButtonStyleSetting(const QString &mainToolBar, const QString &otherToolBars) { KConfigGroup group(KSharedConfig::openConfig(), "Toolbar style"); group.writeEntry("ToolButtonStyle", mainToolBar); group.writeEntry("ToolButtonStyleOtherToolbars", otherToolBars); group.sync(); // Same dbus connect as the one in KToolBar. We want our spy to be notified of receiving it. QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged"), this, SIGNAL(signalAppearanceChanged())); QSignalSpy spy(this, SIGNAL(signalAppearanceChanged())); KToolBar::emitToolbarStyleChanged(); spy.wait(2000); } void tst_KToolBar::deleteGlobalToolButtonStyleSetting() { KConfigGroup group(KSharedConfig::openConfig(), "Toolbar style"); group.deleteEntry("ToolButtonStyle"); group.deleteEntry("ToolButtonStyleOtherToolbars"); KSharedConfig::openConfig()->sync(); } void tst_KToolBar::testToolBarPosition() { TestXmlGuiWindow kmw(m_xml); kmw.createActions(QStringList() << QStringLiteral("go_up")); kmw.createGUI(); KToolBar *mainToolBar = kmw.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = kmw.toolBarByName(QStringLiteral("otherToolBar")); QCOMPARE(kmw.toolBarArea(mainToolBar), Qt::TopToolBarArea); QCOMPARE(kmw.toolBarArea(otherToolBar), Qt::BottomToolBarArea); } void tst_KToolBar::testXmlGuiSwitching() { const QByteArray windowXml = "\n" - "\n" + "\n" "\n" "\n" "\n" "\n"; TestXmlGuiWindow kmw(windowXml); kmw.createActions(QStringList() << QStringLiteral("go_up")); kmw.createGUI(); TestGuiClient firstClient(m_xml); kmw.guiFactory()->addClient(&firstClient); { //qDebug() << "Added gui client"; KToolBar *mainToolBar = firstClient.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = firstClient.toolBarByName(QStringLiteral("otherToolBar")); KToolBar *bigToolBar = firstClient.toolBarByName(QStringLiteral("bigToolBar")); KToolBar *hiddenToolBar = firstClient.toolBarByName(QStringLiteral("hiddenToolBar")); KToolBar *secondHiddenToolBar = firstClient.toolBarByName(QStringLiteral("secondHiddenToolBar")); QCOMPARE(hiddenToolBar->isHidden(), true); QCOMPARE(secondHiddenToolBar->isHidden(), true); // Make (unsaved) changes as user QMetaObject::invokeMethod(mainToolBar, "slotContextTextRight"); // mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); QMetaObject::invokeMethod(mainToolBar, "slotContextRight"); // kmw.addToolBar(Qt::RightToolBarArea, mainToolBar); otherToolBar->setIconDimensions(35); bigToolBar->setIconDimensions(35); bigToolBar->hide(); hiddenToolBar->show(); } kmw.guiFactory()->removeClient(&firstClient); //qDebug() << "Removed gui client"; QVERIFY(!kmw.guiFactory()->container(QStringLiteral("mainToolBar"), &kmw)); QVERIFY(!kmw.guiFactory()->container(QStringLiteral("otherToolBar"), &kmw)); QVERIFY(!kmw.guiFactory()->container(QStringLiteral("bigToolBar"), &kmw)); QVERIFY(!kmw.guiFactory()->container(QStringLiteral("mainToolBar"), &firstClient)); QVERIFY(!kmw.guiFactory()->container(QStringLiteral("otherToolBar"), &firstClient)); QVERIFY(!kmw.guiFactory()->container(QStringLiteral("bigToolBar"), &firstClient)); kmw.guiFactory()->addClient(&firstClient); //qDebug() << "Re-added gui client"; KToolBar *mainToolBar = firstClient.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = firstClient.toolBarByName(QStringLiteral("otherToolBar")); KToolBar *bigToolBar = firstClient.toolBarByName(QStringLiteral("bigToolBar")); KToolBar *cleanToolBar = firstClient.toolBarByName(QStringLiteral("cleanToolBar")); KToolBar *hiddenToolBar = firstClient.toolBarByName(QStringLiteral("hiddenToolBar")); KToolBar *secondHiddenToolBar = firstClient.toolBarByName(QStringLiteral("secondHiddenToolBar")); QCOMPARE((int)mainToolBar->toolButtonStyle(), (int)Qt::ToolButtonTextBesideIcon); QCOMPARE(mainToolBar->isHidden(), false); QCOMPARE(kmw.toolBarArea(mainToolBar), Qt::RightToolBarArea); QCOMPARE(mainToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::MainToolbar)); QCOMPARE(otherToolBar->iconSize().width(), 35); QCOMPARE(bigToolBar->iconSize().width(), 35); QCOMPARE(cleanToolBar->iconSize().width(), KIconLoader::global()->currentSize(KIconLoader::Toolbar)); QCOMPARE(bigToolBar->isHidden(), true); QCOMPARE(hiddenToolBar->isHidden(), false); QCOMPARE(secondHiddenToolBar->isHidden(), true); // Now change KDE-global setting, what happens to unsaved changes? changeGlobalIconSizeSetting(32, 33); QCOMPARE(bigToolBar->iconSize().width(), 35); // fine now, saved or unsaved makes no difference QCOMPARE(otherToolBar->iconSize().width(), 35); // Now save, and check what we saved KConfig config(QStringLiteral("tst_KToolBar")); KConfigGroup group(&config, "group"); kmw.saveMainWindowSettings(group); QCOMPARE(group.group("Toolbar bigToolBar").readEntry("IconSize", 0), 35); QCOMPARE(group.group("Toolbar otherToolBar").readEntry("IconSize", 0), 35); QVERIFY(!group.group("Toolbar cleanToolBar").hasKey("IconSize")); //QCOMPARE(group.group("Toolbar bigToolBar").readEntry("Hidden", false), true); //QVERIFY(!group.group("Toolbar cleanToolBar").hasKey("Hidden")); //QVERIFY(!group.group("Toolbar hiddenToolBar").hasKey("Hidden")); // Recreate window and apply config; is hidden toolbar shown as expected? { TestXmlGuiWindow kmw2(windowXml); kmw2.createActions(QStringList() << QStringLiteral("go_up")); kmw2.createGUI(); TestGuiClient firstClient(m_xml); kmw2.guiFactory()->addClient(&firstClient); KToolBar *mainToolBar = firstClient.toolBarByName(QStringLiteral("mainToolBar")); KToolBar *otherToolBar = firstClient.toolBarByName(QStringLiteral("otherToolBar")); KToolBar *bigToolBar = firstClient.toolBarByName(QStringLiteral("bigToolBar")); KToolBar *hiddenToolBar = firstClient.toolBarByName(QStringLiteral("hiddenToolBar")); KToolBar *secondHiddenToolBar = firstClient.toolBarByName(QStringLiteral("secondHiddenToolBar")); QCOMPARE(bigToolBar->isHidden(), false); QCOMPARE(hiddenToolBar->isHidden(), true); QCOMPARE(secondHiddenToolBar->isHidden(), true); kmw2.show(); // Check that secondHiddenToolBar is not shown+hidden immediately? m_showWasCalled = false; secondHiddenToolBar->installEventFilter(this); kmw2.applyMainWindowSettings(group); QCOMPARE(mainToolBar->isHidden(), false); QCOMPARE(kmw2.toolBarArea(mainToolBar), Qt::RightToolBarArea); QCOMPARE(otherToolBar->iconSize().width(), 35); QCOMPARE(bigToolBar->iconSize().width(), 35); QCOMPARE(bigToolBar->isHidden(), true); QCOMPARE(hiddenToolBar->isHidden(), false); QCOMPARE(secondHiddenToolBar->isHidden(), true); QVERIFY(!m_showWasCalled); } } void tst_KToolBar::testKAuthorizedDisableToggleAction() { TestXmlGuiWindow kmw(m_xml); kmw.createGUI(); foreach (KToolBar *toolbar, kmw.toolBars()) { QVERIFY(!toolbar->toggleViewAction()->isEnabled()); } } bool tst_KToolBar::eventFilter(QObject *watched, QEvent *event) { Q_UNUSED(watched); if (event->type() == QEvent::Show) { m_showWasCalled = true; return true; } return false; } #include "ktoolbar_unittest.moc" diff --git a/autotests/kxmlgui_unittest.cpp b/autotests/kxmlgui_unittest.cpp index 2ecd8ae..9882ab5 100644 --- a/autotests/kxmlgui_unittest.cpp +++ b/autotests/kxmlgui_unittest.cpp @@ -1,1061 +1,1061 @@ /* This file is part of the KDE libraries Copyright 2007-2009 David Faure This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kxmlgui_unittest.h" #include "testxmlguiwindow.h" #include "testguiclient.h" #include #include #include #include #include #include #include #include #include #include #include #include #include // it's not exported, so we need to include the code here #include QTEST_MAIN(KXmlGui_UnitTest) enum Flags { NoFlags = 0, AddToolBars = 1, AddModifiedToolBars = 2, AddActionProperties = 4, AddModifiedMenus = 8 // next item is 16 }; static void createXmlFile(QFile &file, int version, int flags, const QByteArray &toplevelTag = "gui") { const QByteArray xml = "\n" - "\n" + "\n" "<" + toplevelTag + " version=\"" + QByteArray::number(version) + "\" name=\"foo\" >\n" "\n"; file.write(xml); if (flags & AddModifiedMenus) { file.write( "\n" "&File\n" "\n" "\n" ); } file.write("\n"); if (flags & AddToolBars) { file.write( "\n" " Main Toolbar\n" " \n" "\n" "\n" " Bookmark Toolbar\n" "\n" ); } if (flags & AddModifiedToolBars) { file.write( "\n" " Main Toolbar\n" " \n" "\n" "\n" " Modified toolbars\n" "\n" ); } if (flags & AddActionProperties) { file.write( "\n" " \n" "\n" ); } file.write("\n"); } static void clickApply(KEditToolBar *dialog) { QDialogButtonBox *box = dialog->findChild(); Q_ASSERT(box != nullptr); box->button(QDialogButtonBox::Apply)->setEnabled(true); box->button(QDialogButtonBox::Apply)->click(); } void KXmlGui_UnitTest::initTestCase() { QStandardPaths::enableTestMode(true); // Leftover configuration breaks testAutoSaveSettings const QString configFile = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, KSharedConfig::openConfig()->name()); if (!configFile.isEmpty()) { qDebug() << "Removing old config file"; QFile::remove(configFile); KSharedConfig::openConfig()->reparseConfiguration(); } } void KXmlGui_UnitTest::testFindVersionNumber_data() { QTest::addColumn("xml"); QTest::addColumn("version"); QTest::newRow("simple test") << "\n" - "\n" + "\n" "\n" << "3"; QTest::newRow("two digits") << "\n" - "\n" << "42"; + "\n" << "42"; QTest::newRow("with spaces") << // as found in dirfilterplugin.rc for instance "\n" "\n" << "1"; QTest::newRow("with a dot") << // as was found in autorefresh.rc "\n" "\n" << QString() /*error*/; QTest::newRow("with a comment") << // as found in kmail.rc "\n" "\n" - "\n" << "452"; + "\n" << "452"; } void KXmlGui_UnitTest::testFindVersionNumber() { QFETCH(QString, xml); QFETCH(QString, version); QCOMPARE(KXmlGuiVersionHandler::findVersionNumber(xml), version); } void KXmlGui_UnitTest::testVersionHandlerSameVersion() { // This emulates the case where the user has modified stuff locally // and the application hasn't changed since, so the version number is unchanged. QTemporaryFile userFile; QVERIFY(userFile.open()); createXmlFile(userFile, 2, AddActionProperties | AddModifiedToolBars); const QString firstFile = userFile.fileName(); QTemporaryFile appFile; QVERIFY(appFile.open()); createXmlFile(appFile, 2, AddToolBars); const QString secondFile = appFile.fileName(); QStringList files; files << firstFile << secondFile; userFile.close(); appFile.close(); KXmlGuiVersionHandler versionHandler(files); QCOMPARE(versionHandler.finalFile(), firstFile); QString finalDoc = versionHandler.finalDocument(); QVERIFY(finalDoc.startsWith(QStringLiteral(""))); QVERIFY(finalDoc.contains(QStringLiteral("sidebartng"))); // Check that the toolbars modified by the user were kept QVERIFY(finalDoc.contains(QStringLiteral(" fileToVersionMap; // makes QCOMPARE failures more readable than just temp filenames QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); QFile fileV2(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "testui.rc"); QVERIFY2(fileV2.open(QIODevice::WriteOnly), qPrintable(fileV2.fileName())); createXmlFile(fileV2, 2, NoFlags); fileToVersionMap.insert(fileV2.fileName(), 2); QTemporaryFile fileV5; QVERIFY(fileV5.open()); createXmlFile(fileV5, 5, NoFlags); fileToVersionMap.insert(fileV5.fileName(), 5); // The highest version is neither the first nor last one in the list, // to make sure the code really selects the highest version, not just by chance :) // (This is why we add the v1 version at the end of the list) QTemporaryFile fileV1; QVERIFY(fileV1.open()); createXmlFile(fileV1, 1, NoFlags); fileToVersionMap.insert(fileV1.fileName(), 1); QStringList files; files << fileV2.fileName() << fileV5.fileName() << fileV1.fileName(); fileV2.close(); fileV5.close(); fileV1.close(); KXmlGuiVersionHandler versionHandler(files); QCOMPARE(fileToVersionMap.value(versionHandler.finalFile()), 5); QString finalDoc = versionHandler.finalDocument(); QVERIFY(finalDoc.startsWith(QStringLiteral(" fileToVersionMap; // makes QCOMPARE failures more readable than just temp filenames // local file QFile fileV2(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "testui.rc"); QVERIFY(fileV2.open(QIODevice::WriteOnly)); createXmlFile(fileV2, 2, AddActionProperties | AddModifiedToolBars); fileToVersionMap.insert(fileV2.fileName(), 2); // more-global file QTemporaryFile fileV5; QVERIFY(fileV5.open()); createXmlFile(fileV5, 5, AddToolBars | AddModifiedMenus, "kpartgui"); fileToVersionMap.insert(fileV5.fileName(), 5); // The highest version is neither the first nor last one in the list, // to make sure the code really selects the highest version, not just by chance :) // (This is why we add the v1 version at the end of the list) QTemporaryFile fileV1; QVERIFY(fileV1.open()); createXmlFile(fileV1, 1, AddToolBars); fileToVersionMap.insert(fileV1.fileName(), 1); QStringList files; files << fileV2.fileName() << fileV5.fileName() << fileV1.fileName(); fileV2.close(); fileV5.close(); fileV1.close(); KXmlGuiVersionHandler versionHandler(files); // We end up with the local file, so in our map it has version 2. // But of course by now it says "version=5" in it :) QCOMPARE(fileToVersionMap.value(versionHandler.finalFile()), 2); const QString finalDoc = versionHandler.finalDocument(); //qDebug() << finalDoc; QVERIFY(finalDoc.startsWith(QStringLiteral(""))); QVERIFY(finalDoc.contains(QStringLiteral("sidebartng"))); // Check that the menus modified by the app are still there QVERIFY(finalDoc.contains(QStringLiteral(" containers = factory.containers(QStringLiteral("Menu")); QStringList containerNames; Q_FOREACH (QWidget *w, containers) { containerNames << w->objectName(); } return containerNames; } void debugActions(const QList &actions) { Q_FOREACH (QAction *action, actions) { qDebug() << (action->isSeparator() ? QString("separator") : action->objectName()); } } static void checkActions(const QList &actions, const QStringList &expectedActions) { for (int i = 0; i < expectedActions.count(); ++i) { if (i >= actions.count()) break; QAction *action = actions.at(i); if (action->isSeparator()) { QCOMPARE(QStringLiteral("separator"), expectedActions[i]); } else { QCOMPARE(action->objectName(), expectedActions[i]); } } QCOMPARE(actions.count(), expectedActions.count()); } void KXmlGui_UnitTest::testPartMerging() { const QByteArray hostXml = "\n" - "\n" + "\n" "\n" "\n" " &Go\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " Section title\n" " \n" " \n" " &File\n" " \n" " \n" "\n" "\n"; TestGuiClient hostClient; hostClient.createActions(QStringList() << QStringLiteral("go_up") << QStringLiteral("go_back") << QStringLiteral("go_forward") << QStringLiteral("go_home") << QStringLiteral("host_after_merge") << QStringLiteral("host_after_merge_2") << QStringLiteral("last_from_host") << QStringLiteral("file_new") << QStringLiteral("file_open") << QStringLiteral("file_quit")); hostClient.createGUI(hostXml, true /*ui_standards.rc*/); KMainWindow mainWindow; KXMLGUIBuilder builder(&mainWindow); KXMLGUIFactory factory(&builder); factory.addClient(&hostClient); const QString hostDomDoc = hostClient.domDocument().toString(); QWidget *goMenuW = factory.container(QStringLiteral("go"), &hostClient); QVERIFY(goMenuW); QMenu *goMenu = qobject_cast(goMenuW); QVERIFY(goMenu); QMenu *fileMenu = qobject_cast(factory.container(QStringLiteral("file"), &hostClient)); //debugActions(goMenu->actions()); checkActions(goMenu->actions(), QStringList() << QStringLiteral("go_up") << QStringLiteral("go_back") << QStringLiteral("go_forward") << QStringLiteral("go_home") << QStringLiteral("separator") << QStringLiteral("host_after_merge") << QStringLiteral("host_after_merge_2") << QStringLiteral("separator") << QStringLiteral("separator") // separator << QStringLiteral("last_from_host")); checkActions(fileMenu->actions(), QStringList() << QStringLiteral("file_new") << QStringLiteral("file_open") << QStringLiteral("separator") << QStringLiteral("file_quit")); qDebug() << "Now merging the part"; const QByteArray partXml = "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" - "<kpartgui version=\"1\" name=\"part\" >\n" + "<gui version=\"1\" name=\"part\" >\n" "<MenuBar>\n" " <Menu name=\"go\"><text>&Go</text>\n" " <Action name=\"go_previous\" group=\"before_merge\"/>\n" " <Action name=\"go_next\" group=\"before_merge\"/>\n" " <Separator/>\n" " <Action name=\"first_page\"/>\n" " <Action name=\"last_page\"/>\n" " <Title>Part Section\n" " \n" " \n" " \n" " \n" " \n" " &File\n" " \n" " \n" " \n" "\n" - "\n"; + "\n"; TestGuiClient partClient(partXml); partClient.createActions(QStringList() << QStringLiteral("go_previous") << QStringLiteral("go_next") << QStringLiteral("first_page") << QStringLiteral("last_page") << QStringLiteral("last_from_part") << QStringLiteral("action_in_merge_group") << QStringLiteral("undefined_group") << QStringLiteral("action_in_placed_merge") << QStringLiteral("other_file_action") << QStringLiteral("action1") << QStringLiteral("action2")); const QList actionList = { partClient.actionCollection()->action(QStringLiteral("action1")), partClient.actionCollection()->action(QStringLiteral("action2")) }; for (int i = 0 ; i < 5 ; ++i) { //qDebug() << "addClient, iteration" << i; factory.addClient(&partClient); partClient.plugActionList(QStringLiteral("action_list"), actionList); //debugActions(goMenu->actions()); checkActions(goMenu->actions(), QStringList() << QStringLiteral("go_up") << QStringLiteral("go_back") << QStringLiteral("go_forward") << QStringLiteral("go_home") << QStringLiteral("separator") << QStringLiteral("go_previous") << QStringLiteral("go_next") // Contents of the : << QStringLiteral("separator") << QStringLiteral("first_page") << QStringLiteral("last_page") << QStringLiteral("separator") // in the part << QStringLiteral("action1") << QStringLiteral("action2") << QStringLiteral("undefined_group") << QStringLiteral("last_from_part") // End of <Merge> << QStringLiteral("host_after_merge") << QStringLiteral("host_after_merge_2") << QStringLiteral("separator") // Contents of <DefineGroup> << QStringLiteral("action_in_merge_group") // End of <DefineGroup> << QStringLiteral("separator") // <title> is a separator qaction with text << QStringLiteral("last_from_host") ); checkActions(fileMenu->actions(), QStringList() << QStringLiteral("file_new") << QStringLiteral("action_in_placed_merge") << QStringLiteral("file_open") << QStringLiteral("separator") << QStringLiteral("file_quit") << QStringLiteral("other_file_action")); factory.removeClient(&partClient); QCOMPARE(hostClient.domDocument().toString(), hostDomDoc); } factory.removeClient(&hostClient); } void KXmlGui_UnitTest::testPartMergingSettings() // #252911 { const QByteArray hostXml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" // The solution was to remove the duplicated definition // " <Menu name=\"settings\"><text>&Settings</text>\n" // " <Action name=\"options_configure_keybinding\"/>\n" // " <Action name=\"options_configure_toolbars\"/>\n" // " <Merge name=\"configure_merge\"/>\n" // " <Separator/>\n" // " <Merge/>\n" // " </Menu>\n" "</MenuBar></gui>\n"; TestGuiClient hostClient; hostClient.createActions(QStringList() << QStringLiteral("options_configure_keybinding") << QStringLiteral("options_configure_toolbars")); hostClient.createGUI(hostXml, true /*ui_standards.rc*/); //qDebug() << hostClient.domDocument().toString(); KMainWindow mainWindow; KXMLGUIBuilder builder(&mainWindow); KXMLGUIFactory factory(&builder); factory.addClient(&hostClient); QWidget *settingsMenu = qobject_cast<QMenu *>(factory.container(QStringLiteral("settings"), &hostClient)); QVERIFY(settingsMenu); //debugActions(settingsMenu->actions()); const QByteArray partXml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"settings\"><text>&Settings</text>\n" " <Action name=\"configure_klinkstatus\"/>\n" " </Menu>\n" "</MenuBar></gui>\n"; TestGuiClient partClient(partXml); partClient.createActions(QStringList() << QStringLiteral("configure_klinkstatus")); factory.addClient(&partClient); //debugActions(settingsMenu->actions()); checkActions(settingsMenu->actions(), QStringList() << QStringLiteral("separator") // that's ok, QMenuPrivate::filterActions won't show it << QStringLiteral("options_configure_keybinding") << QStringLiteral("options_configure_toolbars") << QStringLiteral("configure_klinkstatus")); factory.removeClient(&partClient); factory.removeClient(&hostClient); } void KXmlGui_UnitTest::testUiStandardsMerging_data() { QTest::addColumn<QByteArray>("xml"); QTest::addColumn<QStringList>("actions"); QTest::addColumn<QStringList>("expectedMenus"); const QByteArray xmlBegin = - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n"; const QByteArray xmlEnd = "</MenuBar>\n" "</gui>"; // Merging an empty menu (or a menu with only non-existing actions) would make // the empty menu appear at the end after all other menus (fixed for KDE-4.2) QTest::newRow("empty file menu, implicit settings menu") << QByteArray(xmlBegin + "<Menu name=\"file\"/>\n" + xmlEnd) << (QStringList() << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("settings")); QTest::newRow("file menu with non existing action, implicit settings menu") << QByteArray(xmlBegin + "<Menu name=\"file\"><Action name=\"foo\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("settings")); QTest::newRow("file menu with existing action, implicit settings menu") << QByteArray(xmlBegin + "<Menu name=\"file\"><Action name=\"open\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("open") << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("file") << QStringLiteral("settings")); QTest::newRow("implicit file and settings menu") << QByteArray(xmlBegin + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("file") << QStringLiteral("settings")); // we could check that file_open is in the mainToolBar, too // Check that unknown non-empty menus are added at the "MergeLocal" position (before settings). QTest::newRow("foo menu added at the end") << QByteArray(xmlBegin + "<Menu name=\"foo\"><Action name=\"foo_action\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("options_configure_toolbars") << QStringLiteral("foo_action")) << (QStringList() << QStringLiteral("file") << QStringLiteral("foo") << QStringLiteral("settings")); QTest::newRow("Bille's testcase: menu patch + menu edit") << QByteArray(xmlBegin + "<Menu name=\"patch\"><Action name=\"patch_generate\"/></Menu>\n" + "<Menu name=\"edit\"><Action name=\"edit_foo\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("patch_generate") << QStringLiteral("edit_foo")) << (QStringList() << QStringLiteral("file") << QStringLiteral("edit") << QStringLiteral("patch")); QTest::newRow("Bille's testcase: menu patch + menu edit, lowercase tag") << QByteArray(xmlBegin + "<Menu name=\"patch\"><Action name=\"patch_generate\"/></Menu>\n" + "<menu name=\"edit\"><Action name=\"edit_foo\"/></menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("patch_generate") << QStringLiteral("edit_foo")) << (QStringList() << QStringLiteral("file") << QStringLiteral("edit") << QStringLiteral("patch")); // Check that <Menu append="..."> allows to insert menus at specific positions QTest::newRow("Menu append") << QByteArray(xmlBegin + "<Menu name=\"foo\" append=\"settings_merge\"><Action name=\"foo_action\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("options_configure_toolbars") << QStringLiteral("foo_action") << QStringLiteral("help_contents")) << (QStringList() << QStringLiteral("file") << QStringLiteral("settings") << QStringLiteral("foo") << QStringLiteral("help")); QTest::newRow("Custom first menu") << QByteArray(xmlBegin + "<Menu name=\"foo\" append=\"first_menu\"><Action name=\"foo_action\"/></Menu>\n" + xmlEnd) << (QStringList() << QStringLiteral("edit_undo") << QStringLiteral("foo_action") << QStringLiteral("help_contents")) << (QStringList() << QStringLiteral("foo") << QStringLiteral("edit") << QStringLiteral("help")); // Tests for noMerge="1" QTest::newRow("noMerge empty file menu, implicit settings menu") << QByteArray(xmlBegin + "<Menu name=\"file\" noMerge=\"1\"/>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("file") << QStringLiteral("settings")); // we keep empty menus, see #186382 QTest::newRow("noMerge empty file menu, file_open moved elsewhere") << QByteArray(xmlBegin + "<Menu name=\"file\" noMerge=\"1\"/>\n<Menu name=\"foo\"><Action name=\"file_open\"/></Menu>" + xmlEnd) << (QStringList() << QStringLiteral("file_open")) << (QStringList() << QStringLiteral("file") << QStringLiteral("foo")); QTest::newRow("noMerge file menu with open before new") << QByteArray(xmlBegin + "<Menu name=\"file\" noMerge=\"1\"><Action name=\"file_open\"/><Action name=\"file_new\"/></Menu>" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("file_new")) << (QStringList() << QStringLiteral("file")); // TODO check the order of the actions in the menu? how? // Tests for deleted="true" QTest::newRow("deleted file menu, implicit settings menu") << QByteArray(xmlBegin + "<Menu name=\"file\" deleted=\"true\"/>\n" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("options_configure_toolbars")) << (QStringList() << QStringLiteral("settings")); QTest::newRow("deleted file menu, file_open moved elsewhere") << QByteArray(xmlBegin + "<Menu name=\"file\" deleted=\"true\"/>\n<Menu name=\"foo\"><Action name=\"file_open\"/></Menu>" + xmlEnd) << (QStringList() << QStringLiteral("file_open")) << (QStringList() << QStringLiteral("foo")); QTest::newRow("deleted file menu with actions (contradiction)") << QByteArray(xmlBegin + "<Menu name=\"file\" deleted=\"true\"><Action name=\"file_open\"/><Action name=\"file_new\"/></Menu>" + xmlEnd) << (QStringList() << QStringLiteral("file_open") << QStringLiteral("file_new")) << (QStringList()); } void KXmlGui_UnitTest::testUiStandardsMerging() { QFETCH(QByteArray, xml); QFETCH(QStringList, actions); QFETCH(QStringList, expectedMenus); TestGuiClient client; client.createActions(actions); client.createGUI(xml, true /*ui_standards.rc*/); const QDomDocument domDocument = client.domDocument(); const QDomElement docElem = domDocument.documentElement(); QCOMPARE(docElem.attribute(QStringLiteral("name")), QStringLiteral("foo")); // not standard_containers from ui_standards.rc QCOMPARE(docElem.attribute(QStringLiteral("version")), QStringLiteral("1")); // not standard_containers from ui_standards.rc KMainWindow mainWindow; KXMLGUIBuilder builder(&mainWindow); KXMLGUIFactory factory(&builder); factory.addClient(&client); const QStringList containerNames = collectMenuNames(factory); //qDebug() << containerNames; QCOMPARE(containerNames, expectedMenus); factory.removeClient(&client); } void KXmlGui_UnitTest::testActionListAndSeparator() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"groups\"><text>Add to Group</text>\n" " <ActionList name=\"view_groups_list\"/>\n" " <Separator />" " <Action name=\"view_add_to_new_group\" />\n" " <ActionList name=\"second_list\"/>\n" " </Menu>\n" "</MenuBar>\n" "</gui>"; TestGuiClient client(xml); client.createActions(QStringList() << QStringLiteral("view_add_to_new_group")); KMainWindow mainWindow; KXMLGUIBuilder builder(&mainWindow); KXMLGUIFactory factory(&builder); factory.addClient(&client); QWidget *menuW = factory.container(QStringLiteral("groups"), &client); QVERIFY(menuW); QMenu *menu = qobject_cast<QMenu *>(menuW); QVERIFY(menu); //debugActions(menu->actions()); checkActions(menu->actions(), QStringList() << QStringLiteral("separator") // that's ok, QMenuPrivate::filterActions won't show it << QStringLiteral("view_add_to_new_group")); qDebug() << "Now plugging the actionlist"; QAction *action1 = new QAction(this); action1->setObjectName(QStringLiteral("action1")); client.actionCollection()->setDefaultShortcut(action1, QKeySequence(QStringLiteral("Ctrl+2"))); QAction *action2 = new QAction(this); action2->setObjectName(QStringLiteral("action2")); const QList<QAction *> actionList = { action1, action2 }; client.plugActionList(QStringLiteral("view_groups_list"), actionList); QCOMPARE(QKeySequence::listToString(action1->shortcuts()), QStringLiteral("Ctrl+2")); const QStringList expectedActionsOneList = { QStringLiteral("action1"), QStringLiteral("action2"), QStringLiteral("separator"), QStringLiteral("view_add_to_new_group") }; //debugActions(menu->actions()); checkActions(menu->actions(), expectedActionsOneList); QAction *action3 = new QAction(this); action3->setObjectName(QStringLiteral("action3")); const QList<QAction *> secondActionList = { action3 }; client.plugActionList(QStringLiteral("second_list"), secondActionList); QStringList expectedActions = expectedActionsOneList; expectedActions << QStringLiteral("action3"); checkActions(menu->actions(), expectedActions); qDebug() << "Now remove+add gui client"; // While I'm here, what happens with the action list if I remove+add the guiclient, // like KXmlGuiWindow::newToolBarConfig does? factory.removeClient(&client); factory.addClient(&client); // We need to get the container widget again, it was re-created. menuW = factory.container(QStringLiteral("groups"), &client); QVERIFY(menuW); menu = qobject_cast<QMenu *>(menuW); //debugActions(menu->actions()); checkActions(menu->actions(), QStringList() << QStringLiteral("separator") // yep, it removed the actionlist thing... << QStringLiteral("view_add_to_new_group")); qDebug() << "Now plugging the actionlist again"; client.plugActionList(QStringLiteral("second_list"), secondActionList); client.plugActionList(QStringLiteral("view_groups_list"), actionList); checkActions(menu->actions(), expectedActions); factory.removeClient(&client); } void KXmlGui_UnitTest::testHiddenToolBar() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" "</MenuBar>\n" "<ToolBar hidden=\"true\" name=\"mainToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "<ToolBar name=\"visibleToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "<ToolBar hidden=\"true\" name=\"hiddenToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "</gui>\n"; KConfigGroup cg(KSharedConfig::openConfig(), "testHiddenToolBar"); TestXmlGuiWindow mainWindow(xml); mainWindow.setAutoSaveSettings(cg); mainWindow.createActions(QStringList() << QStringLiteral("go_up")); mainWindow.createGUI(); KToolBar *mainToolBar = mainWindow.toolBarByName(QStringLiteral("mainToolBar")); QVERIFY(mainToolBar->isHidden()); KXMLGUIFactory *factory = mainWindow.guiFactory(); QVERIFY(!factory->container(QStringLiteral("visibleToolBar"), &mainWindow)->isHidden()); KToolBar *hiddenToolBar = qobject_cast<KToolBar *>(factory->container(QStringLiteral("hiddenToolBar"), &mainWindow)); qDebug() << hiddenToolBar; QVERIFY(hiddenToolBar->isHidden()); // Now open KEditToolBar (#105525) KEditToolBar editToolBar(factory); // KEditToolBar loads the stuff in showEvent... QShowEvent ev; qApp->sendEvent(&editToolBar, &ev); clickApply(&editToolBar); QVERIFY(qobject_cast<KToolBar *>(factory->container(QStringLiteral("hiddenToolBar"), &mainWindow))->isHidden()); mainWindow.close(); } // taken from KMainWindow_UnitTest::testAutoSaveSettings() void KXmlGui_UnitTest::testAutoSaveSettings() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" "</MenuBar>\n" "<ToolBar name=\"mainToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "<ToolBar name=\"secondToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "</gui>\n"; { // do not interfere with the "toolbarVisibility" unit test KConfigGroup cg(KSharedConfig::openConfig(), "testAutoSaveSettings"); TestXmlGuiWindow mw(xml); mw.show(); mw.setAutoSaveSettings(cg); // Test resizing first (like show() does). mw.reallyResize(400, 400); QTest::qWait(200); mw.createActions(QStringList() << QStringLiteral("go_up")); mw.createGUI(); // Resize again, should be saved mw.reallyResize(800, 600); QTest::qWait(200); KToolBar *mainToolBar = mw.toolBarByName(QStringLiteral("mainToolBar")); QCOMPARE(mw.toolBarArea(mainToolBar), Qt::TopToolBarArea); KToolBar *secondToolBar = mw.toolBarByName(QStringLiteral("secondToolBar")); QCOMPARE((int)mw.toolBarArea(secondToolBar), (int)Qt::TopToolBarArea); // REFERENCE #1 (see below) // Move second toolbar to bottom const QPoint oldPos = secondToolBar->pos(); mw.addToolBar(Qt::BottomToolBarArea, secondToolBar); const QPoint newPos = secondToolBar->pos(); QCOMPARE(mw.toolBarArea(secondToolBar), Qt::BottomToolBarArea); // Calling to addToolBar is not enough to trigger the event filter for move events // in KMainWindow, because there is no layouting happening in hidden mainwindows. QMoveEvent moveEvent(newPos, oldPos); QApplication::sendEvent(secondToolBar, &moveEvent); mw.close(); } { KConfigGroup cg(KSharedConfig::openConfig(), "testAutoSaveSettings"); TestXmlGuiWindow mw2(xml); mw2.show(); mw2.setAutoSaveSettings(cg); QTest::qWait(200); // Check window size was restored QCOMPARE(mw2.size(), QSize(800, 600)); mw2.createActions(QStringList() << QStringLiteral("go_up")); mw2.createGUI(); // Force window layout to happen mw2.reallyResize(800, 600); QTest::qWait(200); // Check toolbar positions were restored KToolBar *mainToolBar = mw2.toolBarByName(QStringLiteral("mainToolBar")); QCOMPARE(mw2.toolBarArea(mainToolBar), Qt::TopToolBarArea); KToolBar *secondToolBar = mw2.toolBarByName(QStringLiteral("secondToolBar")); QCOMPARE(mw2.toolBarArea(secondToolBar), Qt::BottomToolBarArea); mw2.applyMainWindowSettings(mw2.autoSaveConfigGroup()); QCOMPARE(mw2.toolBarArea(secondToolBar), Qt::BottomToolBarArea); } } void KXmlGui_UnitTest::testDeletedContainers() // deleted="true" { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu deleted=\"true\" name=\"game\"/>\n" "</MenuBar>\n" "<ToolBar deleted=\"true\" name=\"mainToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "<ToolBar name=\"visibleToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "<ToolBar deleted=\"true\" name=\"deletedToolBar\">\n" " <Action name=\"go_up\"/>\n" "</ToolBar>\n" "</gui>\n"; KConfigGroup cg(KSharedConfig::openConfig(), "testDeletedToolBar"); TestXmlGuiWindow mainWindow(xml); mainWindow.setAutoSaveSettings(cg); mainWindow.createActions(QStringList() << QStringLiteral("go_up") << QStringLiteral("file_new") << QStringLiteral("game_new")); mainWindow.createGUI(); KXMLGUIFactory *factory = mainWindow.guiFactory(); //qDebug() << "containers:" << factory->containers("ToolBar"); QVERIFY(!factory->container(QStringLiteral("mainToolBar"), &mainWindow)); QVERIFY(!factory->container(QStringLiteral("visibleToolBar"), &mainWindow)->isHidden()); QVERIFY(!factory->container(QStringLiteral("deletedToolBar"), &mainWindow)); QVERIFY(factory->container(QStringLiteral("file"), &mainWindow)); // File menu was created QVERIFY(!factory->container(QStringLiteral("game"), &mainWindow)); // Game menu was not created // Now open KEditToolBar, just to check it doesn't crash. KEditToolBar editToolBar(factory); // KEditToolBar loads the stuff in showEvent... QShowEvent ev; qApp->sendEvent(&editToolBar, &ev); clickApply(&editToolBar); QVERIFY(!factory->container(QStringLiteral("mainToolBar"), &mainWindow)); QVERIFY(!factory->container(QStringLiteral("visibleToolBar"), &mainWindow)->isHidden()); QVERIFY(!factory->container(QStringLiteral("deletedToolBar"), &mainWindow)); QVERIFY(factory->container(QStringLiteral("file"), &mainWindow)); QVERIFY(!factory->container(QStringLiteral("game"), &mainWindow)); mainWindow.close(); } void KXmlGui_UnitTest::testTopLevelSeparator() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"before_separator\"><text>Before Separator</text></Menu>\n" " <Separator />\n" " <Menu name=\"after_separator\"><text>After Separator</text></Menu>\n" "</MenuBar>\n" "</gui>"; TestXmlGuiWindow mainWindow(xml); mainWindow.createGUI(); checkActions(mainWindow.menuBar()->actions(), QStringList() << QStringLiteral("before_separator") << QStringLiteral("separator") << QStringLiteral("after_separator") << QStringLiteral("separator") << QStringLiteral("help")); } // Check that the objectName() of the menus is set from the name in the XML file void KXmlGui_UnitTest::testMenuNames() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"filemenu\"><text>File Menu</text></Menu>\n" "</MenuBar>\n" "</gui>"; TestXmlGuiWindow mainWindow(xml); mainWindow.createGUI(); checkActions(mainWindow.menuBar()->actions(), QStringList() << QStringLiteral("filemenu") << QStringLiteral("separator") << QStringLiteral("help")); } // Test what happens when the application's rc file isn't found // We want a warning to be printed, but we don't want to see all menus from ui_standards.rc void KXmlGui_UnitTest::testMenusNoXmlFile() { TestXmlGuiWindow mainWindow; mainWindow.createGUIBad(); checkActions(mainWindow.menuBar()->actions(), QStringList() << QStringLiteral("help")); } void KXmlGui_UnitTest::testXMLFileReplacement() { // to differentiate "original" and replacement xml file, one is created with "modified" toolbars QTemporaryFile fileOrig; QVERIFY(fileOrig.open()); createXmlFile(fileOrig, 2, AddToolBars); const QString filenameOrig = fileOrig.fileName(); fileOrig.close(); QTemporaryFile fileReplace; QVERIFY(fileReplace.open()); createXmlFile(fileReplace, 2, AddModifiedToolBars); const QString filenameReplace = fileReplace.fileName(); fileReplace.close(); // finally, our local xml file has <ActionProperties/> QFile fileLocal(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "testui.rc"); QVERIFY(fileLocal.open(QIODevice::WriteOnly)); createXmlFile(fileLocal, 1, AddActionProperties); const QString filenameLocal = fileLocal.fileName(); fileLocal.close(); TestGuiClient client; // first make sure that the "original" file is loaded, correctly client.setXMLFilePublic(filenameOrig); QString xml = client.domDocument().toString(); //qDebug() << xml; QVERIFY(xml.contains(QStringLiteral("<Action name=\"print\""))); QVERIFY(!xml.contains(QStringLiteral("<Action name=\"home\""))); QVERIFY(!xml.contains(QStringLiteral("<ActionProperties>"))); // now test the replacement (+ local file) client.replaceXMLFile(filenameReplace, filenameLocal); xml = client.domDocument().toString(); QVERIFY(!xml.contains(QStringLiteral("<Action name=\"print\""))); QVERIFY(xml.contains(QStringLiteral("<Action name=\"home\""))); QVERIFY(xml.contains(QStringLiteral("<ActionProperties>"))); // re-check after a reload client.reloadXML(); QString reloadedXml = client.domDocument().toString(); QVERIFY(!reloadedXml.contains(QStringLiteral("<Action name=\"print\""))); QVERIFY(reloadedXml.contains(QStringLiteral("<Action name=\"home\""))); QVERIFY(reloadedXml.contains(QStringLiteral("<ActionProperties>"))); // Check what happens when the local file doesn't exist TestGuiClient client2; QFile::remove(filenameLocal); client2.replaceXMLFile(filenameReplace, filenameLocal); xml = client2.domDocument().toString(); //qDebug() << xml; QVERIFY(!xml.contains(QStringLiteral("<Action name=\"print\""))); QVERIFY(xml.contains(QStringLiteral("<Action name=\"home\""))); // modified toolbars QVERIFY(!xml.contains(QStringLiteral("<ActionProperties>"))); // but no local xml file } void KXmlGui_UnitTest::testClientDestruction() // #170806 { const QByteArray hostXml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"file\"><text>&File</text>\n" " </Menu>\n" " <Merge/>\n" "</MenuBar>\n" "</gui>"; const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"file\"><text>&File</text>\n" " <Action name=\"file_open\"/>\n" " <Action name=\"file_quit\"/>\n" " </Menu>\n" "</MenuBar>\n" "</gui>"; TestXmlGuiWindow mainWindow(hostXml); TestGuiClient *client = new TestGuiClient(xml); client->createActions(QStringList() << QStringLiteral("file_open") << QStringLiteral("file_quit")); mainWindow.insertChildClient(client); mainWindow.createGUI(); checkActions(mainWindow.menuBar()->actions(), QStringList() << QStringLiteral("file") << QStringLiteral("separator") << QStringLiteral("help")); QVERIFY(mainWindow.factory()->clients().contains(client)); delete client; QVERIFY(!mainWindow.factory()->clients().contains(client)); // No change, because deletion is fast, it doesn't do manual unplugging. checkActions(mainWindow.menuBar()->actions(), QStringList() << QStringLiteral("file") << QStringLiteral("separator") << QStringLiteral("help")); } void KXmlGui_UnitTest::testShortcuts() { const QByteArray xml = "<?xml version = '1.0'?>\n" - "<!DOCTYPE gui SYSTEM \"kpartgui.dtd\">\n" + "<!DOCTYPE kpartgui SYSTEM \"kpartgui.dtd\">\n" "<gui version=\"1\" name=\"foo\" >\n" "<MenuBar>\n" " <Menu name=\"file\"><text>&File</text>\n" " <Action name=\"file_open\" shortcut=\"Ctrl+O\"/>\n" " <Action name=\"file_quit\" shortcut=\"Ctrl+Q; Ctrl+D\"/>\n" " </Menu>\n" "</MenuBar>\n" "<ActionProperties scheme=\"Default\">\n" " <Action shortcut=\"Ctrl+O\" name=\"file_open\"/>\n" " <Action shortcut=\"Ctrl+Q; Ctrl+D\" name=\"file_quit\"/>\n" "</ActionProperties>\n" "</gui>"; TestGuiClient client; client.createActions(QStringList() << QStringLiteral("file_open") << QStringLiteral("file_quit")); client.createGUI(xml, false /*ui_standards.rc*/); KMainWindow mainWindow; KXMLGUIBuilder builder(&mainWindow); KXMLGUIFactory factory(&builder); factory.addClient(&client); QAction* actionOpen = client.action("file_open"); QAction* actionQuit = client.action("file_quit"); QVERIFY(actionOpen && actionQuit); QCOMPARE(actionOpen->shortcuts(), QList<QKeySequence>() << QKeySequence(QStringLiteral("Ctrl+O"))); // #345411 QCOMPARE(actionQuit->shortcuts(), QList<QKeySequence>() << QKeySequence(QStringLiteral("Ctrl+Q")) << QKeySequence(QStringLiteral("Ctrl+D"))); factory.removeClient(&client); } diff --git a/src/kshortcutschemeseditor.cpp b/src/kshortcutschemeseditor.cpp index 4df982d..9855220 100644 --- a/src/kshortcutschemeseditor.cpp +++ b/src/kshortcutschemeseditor.cpp @@ -1,210 +1,210 @@ /* This file is part of the KDE libraries Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kshortcutsdialog_p.h" #include <QDir> #include <QLabel> #include <QMenu> #include <QFile> #include <QPushButton> #include <QTextStream> #include <QtXml/QDomDocument> #include <QFileDialog> #include <QStandardPaths> #include <QInputDialog> #include <QComboBox> #include <kconfiggroup.h> #include <kmessagebox.h> #include <ksharedconfig.h> #include "kshortcutsdialog.h" #include "kshortcutschemeshelper_p.h" #include "kactioncollection.h" #include "kxmlguiclient.h" #include <debug.h> KShortcutSchemesEditor::KShortcutSchemesEditor(KShortcutsDialog *parent) : QGroupBox(i18n("Shortcut Schemes"), parent), m_dialog(parent) { KConfigGroup group(KSharedConfig::openConfig(), "Shortcut Schemes"); QStringList schemes; schemes << QStringLiteral("Default"); // List files in the shortcuts subdir, each one is a scheme. See KShortcutSchemesHelper::{shortcutSchemeFileName,exportActionCollection} const QStringList shortcutsDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QCoreApplication::applicationName() + QStringLiteral("/shortcuts"), QStandardPaths::LocateDirectory); qCDebug(DEBUG_KXMLGUI) << "shortcut scheme dirs:" << shortcutsDirs; Q_FOREACH (const QString &dir, shortcutsDirs) { Q_FOREACH (const QString &file, QDir(dir).entryList(QDir::Files | QDir::NoDotAndDotDot)) { qCDebug(DEBUG_KXMLGUI) << "shortcut scheme file:" << file; schemes << file; } } const QString currentScheme = group.readEntry("Current Scheme", "Default"); qCDebug(DEBUG_KXMLGUI) << "Current Scheme" << currentScheme; QHBoxLayout *l = new QHBoxLayout(this); QLabel *schemesLabel = new QLabel(i18n("Current scheme:"), this); l->addWidget(schemesLabel); m_schemesList = new QComboBox(this); m_schemesList->setEditable(false); m_schemesList->addItems(schemes); m_schemesList->setSizeAdjustPolicy(QComboBox::AdjustToContents); const int schemeIdx = m_schemesList->findText(currentScheme); if (schemeIdx > -1) { m_schemesList->setCurrentIndex(schemeIdx); } else { qCWarning(DEBUG_KXMLGUI) << "Current scheme" << currentScheme << "not found in" << shortcutsDirs; } schemesLabel->setBuddy(m_schemesList); l->addWidget(m_schemesList); m_newScheme = new QPushButton(i18n("New...")); l->addWidget(m_newScheme); m_deleteScheme = new QPushButton(i18n("Delete")); l->addWidget(m_deleteScheme); QPushButton *moreActions = new QPushButton(i18n("More Actions")); l->addWidget(moreActions); QMenu *moreActionsMenu = new QMenu(this); moreActionsMenu->addAction(i18n("Save shortcuts to scheme"), this, SLOT(saveAsDefaultsForScheme())); moreActionsMenu->addAction(i18n("Export Scheme..."), this, SLOT(exportShortcutsScheme())); moreActionsMenu->addAction(i18n("Import Scheme..."), this, SLOT(importShortcutsScheme())); moreActions->setMenu(moreActionsMenu); l->addStretch(1); connect(m_schemesList, SIGNAL(activated(QString)), this, SIGNAL(shortcutsSchemeChanged(QString))); connect(m_newScheme, SIGNAL(clicked()), this, SLOT(newScheme())); connect(m_deleteScheme, SIGNAL(clicked()), this, SLOT(deleteScheme())); updateDeleteButton(); } void KShortcutSchemesEditor::newScheme() { bool ok; const QString newName = QInputDialog::getText(this, i18n("Name for New Scheme"), i18n("Name for new scheme:"), QLineEdit::Normal, i18n("New Scheme"), &ok); if (!ok) { return; } if (m_schemesList->findText(newName) != -1) { KMessageBox::sorry(this, i18n("A scheme with this name already exists.")); return; } const QString newSchemeFileName = KShortcutSchemesHelper::writableApplicationShortcutSchemeFileName(newName); QDir().mkpath(QFileInfo(newSchemeFileName).absolutePath()); QFile schemeFile(newSchemeFileName); if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate)) { qCWarning(DEBUG_KXMLGUI) << "Couldn't write to" << newSchemeFileName; return; } QDomDocument doc; - QDomElement docElem = doc.createElement(QStringLiteral("kpartgui")); + QDomElement docElem = doc.createElement(QStringLiteral("gui")); doc.appendChild(docElem); QDomElement elem = doc.createElement(QStringLiteral("ActionProperties")); docElem.appendChild(elem); QTextStream out(&schemeFile); out << doc.toString(4); m_schemesList->addItem(newName); m_schemesList->setCurrentIndex(m_schemesList->findText(newName)); updateDeleteButton(); emit shortcutsSchemeChanged(newName); } void KShortcutSchemesEditor::deleteScheme() { if (KMessageBox::questionYesNo(this, i18n("Do you really want to delete the scheme %1?\n\ Note that this will not remove any system wide shortcut schemes.", currentScheme())) == KMessageBox::No) { return; } //delete the scheme for the app itself QFile::remove(KShortcutSchemesHelper::writableApplicationShortcutSchemeFileName(currentScheme())); //delete all scheme files we can find for xmlguiclients in the user directories foreach (KActionCollection *collection, m_dialog->actionCollections()) { const KXMLGUIClient *client = collection->parentGUIClient(); if (!client) { continue; } QFile::remove(KShortcutSchemesHelper::writableShortcutSchemeFileName(client->componentName(), currentScheme())); } m_schemesList->removeItem(m_schemesList->findText(currentScheme())); updateDeleteButton(); emit shortcutsSchemeChanged(currentScheme()); } QString KShortcutSchemesEditor::currentScheme() { return m_schemesList->currentText(); } void KShortcutSchemesEditor::exportShortcutsScheme() { //ask user about dir QString path = QFileDialog::getSaveFileName(this, i18n("Export Shortcuts"), QDir::currentPath(), i18n("Shortcuts (*.shortcuts)")); if (path.isEmpty()) { return; } m_dialog->exportConfiguration(path); } void KShortcutSchemesEditor::importShortcutsScheme() { //ask user about dir QString path = QFileDialog::getOpenFileName(this, i18n("Import Shortcuts"), QDir::currentPath(), i18n("Shortcuts (*.shortcuts)")); if (path.isEmpty()) { return; } m_dialog->importConfiguration(path); } void KShortcutSchemesEditor::saveAsDefaultsForScheme() { if (KShortcutSchemesHelper::saveShortcutScheme(m_dialog->actionCollections(), currentScheme())) { KMessageBox::information(this, i18n("Shortcut scheme successfully saved.")); } else { // We'd need to return to return more than a bool, to show more details here. KMessageBox::sorry(this, i18n("Error saving the shortcut scheme.")); } } void KShortcutSchemesEditor::updateDeleteButton() { m_deleteScheme->setEnabled(m_schemesList->count() >= 1); } diff --git a/src/kshortcutschemeshelper.cpp b/src/kshortcutschemeshelper.cpp index a63f51e..4fa3116 100644 --- a/src/kshortcutschemeshelper.cpp +++ b/src/kshortcutschemeshelper.cpp @@ -1,142 +1,142 @@ /* This file is part of the KDE libraries Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kshortcutschemeshelper_p.h" #include <QAction> #include <QCoreApplication> #include <QFile> #include <QTextStream> #include <QtXml/QDomDocument> #include <QStandardPaths> #include <QDir> #include <kconfiggroup.h> #include <ksharedconfig.h> #include "kactioncollection.h" #include "kxmlguiclient.h" #include "debug.h" bool KShortcutSchemesHelper::saveShortcutScheme(const QList<KActionCollection *> &collections, const QString &schemeName) { // Every action collection is associated with a KXMLGUIClient // (at least if it was added by KXMLGUIFactory::configureShortcuts) // Some GUI clients have the same name (e.g. the child client for a mainwindow // holding the actions for hiding/showing toolbars), so we need to save them // together, otherwise they will overwrite each other's file on disk. // For cases like kdevelop (many guiclients not reused in other apps) it's simpler // to even save all shortcuts to a single shortcuts file -> set the boolean below to true // to create an all-in-one scheme. // Maybe we need a checkbox for this? Or an env var for contributors to set, rather? End users don't care. const bool saveToApplicationFile = false; QMap<QString, KActionCollection *> collectionsByClientName; foreach (KActionCollection *coll, collections) { const KXMLGUIClient *client = coll->parentGUIClient(); if (client) { const QString key = saveToApplicationFile ? QCoreApplication::applicationName() : client->componentName(); collectionsByClientName.insertMulti(key, coll); } } foreach (const QString &componentName, collectionsByClientName.uniqueKeys()) { qCDebug(DEBUG_KXMLGUI) << "Considering component" << componentName; QDomDocument doc; - QDomElement docElem = doc.createElement(QStringLiteral("kpartgui")); + QDomElement docElem = doc.createElement(QStringLiteral("gui")); docElem.setAttribute(QStringLiteral("version"), QStringLiteral("1")); docElem.setAttribute(QStringLiteral("name"), componentName); doc.appendChild(docElem); QDomElement elem = doc.createElement(QStringLiteral("ActionProperties")); docElem.appendChild(elem); foreach (KActionCollection *collection, collectionsByClientName.values(componentName)) { qCDebug(DEBUG_KXMLGUI) << "Saving shortcut scheme for action collection with" << collection->actions().count() << "actions"; foreach (QAction *action, collection->actions()) { if (!action) { continue; } const QString actionName = action->objectName(); const QString shortcut = QKeySequence::listToString(action->shortcuts()); //qCDebug(DEBUG_KXMLGUI) << "action" << actionName << "has shortcut" << shortcut; if (!shortcut.isEmpty()) { QDomElement act_elem = doc.createElement(QStringLiteral("Action")); act_elem.setAttribute(QStringLiteral("name"), actionName); act_elem.setAttribute(QStringLiteral("shortcut"), shortcut); elem.appendChild(act_elem); } } } const QString schemeFileName = writableShortcutSchemeFileName(componentName, schemeName); if (elem.childNodes().isEmpty()) { QFile::remove(schemeFileName); } else { qCDebug(DEBUG_KXMLGUI) << "saving to" << schemeFileName; QDir().mkpath(QFileInfo(schemeFileName).absolutePath()); QFile schemeFile(schemeFileName); if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate)) { qCDebug(DEBUG_KXMLGUI) << "COULD NOT WRITE" << schemeFileName; return false; } QTextStream out(&schemeFile); out << doc.toString(2); } } return true; } QString KShortcutSchemesHelper::currentShortcutSchemeName() { return KSharedConfig::openConfig()->group("Shortcut Schemes").readEntry("Current Scheme", "Default"); } QString KShortcutSchemesHelper::writableShortcutSchemeFileName(const QString &componentName, const QString &schemeName) { return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + componentName + QStringLiteral("/shortcuts/") + schemeName; } QString KShortcutSchemesHelper::writableApplicationShortcutSchemeFileName(const QString &schemeName) { return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + QCoreApplication::applicationName() + QStringLiteral("/shortcuts/") + schemeName; } QString KShortcutSchemesHelper::shortcutSchemeFileName(const QString &componentName, const QString &schemeName) { return QStandardPaths::locate(QStandardPaths::GenericDataLocation, componentName + QStringLiteral("/shortcuts/") + schemeName); } QString KShortcutSchemesHelper::applicationShortcutSchemeFileName(const QString &schemeName) { return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QCoreApplication::applicationName() + QStringLiteral("/shortcuts/") + schemeName); } diff --git a/src/ktoolbarhandler.cpp b/src/ktoolbarhandler.cpp index e671c8d..57843f6 100644 --- a/src/ktoolbarhandler.cpp +++ b/src/ktoolbarhandler.cpp @@ -1,270 +1,270 @@ /* This file is part of the KDE libraries Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ktoolbarhandler_p.h" #include <QtXml/QDomDocument> #include <QAction> #include <QMenu> #include <kactionmenu.h> #include <kauthorized.h> #include <klocalizedstring.h> #include "kxmlguiwindow.h" #include "ktoggletoolbaraction.h" #include "ktoolbar.h" #include "kxmlguifactory.h" #include "kactioncollection.h" namespace { const char actionListName[] = "show_menu_and_toolbar_actionlist"; const char guiDescription[] = "" - "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">" + "<!DOCTYPE kpartgui><gui name=\"StandardToolBarMenuHandler\">" "<MenuBar>" " <Menu name=\"settings\">" " <ActionList name=\"%1\" />" " </Menu>" "</MenuBar>" - "</kpartgui>"; + "</gui>"; class BarActionBuilder { public: BarActionBuilder(KActionCollection *actionCollection, KXmlGuiWindow *mainWindow, QLinkedList<KToolBar *> &oldToolBarList) : m_actionCollection(actionCollection), m_mainWindow(mainWindow), m_needsRebuild(false) { QList<KToolBar *> toolBars = m_mainWindow->findChildren<KToolBar *>(); Q_FOREACH (KToolBar *toolBar, toolBars) { if (toolBar->mainWindow() != m_mainWindow) { continue; } if (!oldToolBarList.contains(toolBar)) { m_needsRebuild = true; } m_toolBars.append(toolBar); } if (!m_needsRebuild) { m_needsRebuild = (oldToolBarList.count() != m_toolBars.count()); } } bool needsRebuild() const { return m_needsRebuild; } QList<QAction *> create() { QList<QAction *> actions; if (!m_needsRebuild) { return actions; } Q_FOREACH (KToolBar *bar, m_toolBars) { handleToolBar(bar); } if (m_toolBarActions.count() == 0) { return actions; } if (m_toolBarActions.count() == 1) { KToggleToolBarAction *action = static_cast<KToggleToolBarAction *>(m_toolBarActions.first()); action->setText(KStandardShortcut::label(KStandardShortcut::ShowToolbar)); return m_toolBarActions; } KActionMenu *menuAction = new KActionMenu(i18n("Toolbars Shown"), m_actionCollection); m_actionCollection->addAction(QStringLiteral("toolbars_submenu_action"), menuAction); Q_FOREACH (QAction *action, m_toolBarActions) { menuAction->menu()->addAction(action); } actions.append(menuAction); return actions; } const QLinkedList<KToolBar *> &toolBars() const { return m_toolBars; } private: void handleToolBar(KToolBar *toolBar) { KToggleToolBarAction *action = new KToggleToolBarAction( toolBar, toolBar->windowTitle(), m_actionCollection); m_actionCollection->addAction(toolBar->objectName(), action); // ## tooltips, whatsthis? m_toolBarActions.append(action); } KActionCollection *m_actionCollection; KXmlGuiWindow *m_mainWindow; QLinkedList<KToolBar *> m_toolBars; QList<QAction *> m_toolBarActions; bool m_needsRebuild : 1; }; } using namespace KDEPrivate; class ToolBarHandler::Private { public: Private(ToolBarHandler *_parent) : parent(_parent) { } void clientAdded(KXMLGUIClient *client) { Q_UNUSED(client) parent->setupActions(); } void init(KXmlGuiWindow *mainWindow); void connectToActionContainers(); void connectToActionContainer(QAction *action); void connectToActionContainer(QWidget *container); ToolBarHandler *parent; QPointer<KXmlGuiWindow> mainWindow; QList<QAction *> actions; QLinkedList<KToolBar *> toolBars; }; void ToolBarHandler::Private::init(KXmlGuiWindow *mw) { mainWindow = mw; QObject::connect(mainWindow->guiFactory(), SIGNAL(clientAdded(KXMLGUIClient*)), parent, SLOT(clientAdded(KXMLGUIClient*))); if (parent->domDocument().documentElement().isNull()) { QString completeDescription = QString::fromLatin1(guiDescription) .arg(QLatin1String(actionListName)); parent->setXML(completeDescription, false /*merge*/); } } void ToolBarHandler::Private::connectToActionContainers() { Q_FOREACH (QAction *action, actions) { connectToActionContainer(action); } } void ToolBarHandler::Private::connectToActionContainer(QAction *action) { uint containerCount = action->associatedWidgets().count(); for (uint i = 0; i < containerCount; ++i) { connectToActionContainer(action->associatedWidgets().value(i)); } } void ToolBarHandler::Private::connectToActionContainer(QWidget *container) { QMenu *popupMenu = qobject_cast<QMenu *>(container); if (!popupMenu) { return; } connect(popupMenu, SIGNAL(aboutToShow()), parent, SLOT(setupActions())); } ToolBarHandler::ToolBarHandler(KXmlGuiWindow *mainWindow) : QObject(mainWindow), KXMLGUIClient(mainWindow), d(new Private(this)) { d->init(mainWindow); } ToolBarHandler::ToolBarHandler(KXmlGuiWindow *mainWindow, QObject *parent) : QObject(parent), KXMLGUIClient(mainWindow), d(new Private(this)) { d->init(mainWindow); } ToolBarHandler::~ToolBarHandler() { qDeleteAll(d->actions); d->actions.clear(); delete d; } QAction *ToolBarHandler::toolBarMenuAction() { Q_ASSERT(d->actions.count() == 1); return d->actions.first(); } void ToolBarHandler::setupActions() { if (!factory() || !d->mainWindow) { return; } BarActionBuilder builder(actionCollection(), d->mainWindow, d->toolBars); if (!builder.needsRebuild()) { return; } unplugActionList(QLatin1String(actionListName)); qDeleteAll(d->actions); d->actions.clear(); d->actions = builder.create(); d->toolBars = builder.toolBars(); // We have no XML file associated with our action collection, so load settings from KConfig actionCollection()->readSettings(); // #233712 if (KAuthorized::authorizeAction(QStringLiteral("options_show_toolbar"))) { plugActionList(QLatin1String(actionListName), d->actions); } d->connectToActionContainers(); } #include "moc_ktoolbarhandler_p.cpp" diff --git a/src/ui_standards.rc b/src/ui_standards.rc index 0501600..ed078d1 100644 --- a/src/ui_standards.rc +++ b/src/ui_standards.rc @@ -1,221 +1,221 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="standard_containers" version="18" translationDomain="kxmlgui5"> +<gui name="standard_containers" version="18" translationDomain="kxmlgui5"> <MenuBar> <MergeLocal name="first_menu"/> <Menu name="file"><text>&File</text> <Action name="file_new"/> <MergeLocal name="new_merge"/> <Action name="file_open"/> <Action name="file_open_recent"/> <MergeLocal name="open_merge"/> <Separator/> <Action name="file_save"/> <Action name="file_save_as"/> <Action name="file_save_all"/> <MergeLocal name="save_merge"/> <Action name="file_revert"/> <Action name="file_revert_all"/> <MergeLocal name="revert_merge"/> <Separator/> <Action name="file_print"/> <Action name="file_print_preview"/> <MergeLocal name="print_merge"/> <Action name="file_mail"/> <MergeLocal name="mail_merge"/> <Separator/> <MergeLocal/> <Separator/> <Action name="file_close"/> <Action name="file_close_all"/> <MergeLocal name="close_merge"/> <Separator/> <Action name="file_quit"/> </Menu> <Menu name="game"><text>&Game</text> <Action name="game_new"/> <Action name="game_load"/> <Action name="game_load_recent"/> <Action name="game_restart"/> <MergeLocal name="new_merge"/> <Separator/> <Action name="game_save"/> <Action name="game_save_as"/> <MergeLocal name="save_merge"/> <Separator/> <Action name="game_end"/> <MergeLocal name="end_merge"/> <Separator/> <Action name="game_pause"/> <Action name="game_highscores"/> <Action name="game_clear_highscores"/> <Action name="game_statistics"/> <Action name="game_clear_statistics"/> <Action name="game_print"/> <Action name="game_print_preview"/> <MergeLocal name="misc_merge"/> <Separator/> <MergeLocal/> <Separator/> <Action name="game_quit"/> </Menu> <Menu name="edit"><text>&Edit</text> <Action name="edit_undo"/> <Action name="edit_redo"/> <MergeLocal name="edit_undo_merge"/> <Separator/> <Action name="edit_cut"/> <Action name="edit_copy"/> <Action name="edit_paste"/> <MergeLocal name="edit_paste_merge"/> <Action name="edit_clear"/> <Separator/> <Action name="edit_select_all"/> <Action name="edit_deselect"/> <MergeLocal name="edit_select_merge"/> <Separator/> <Action name="edit_find"/> <Action name="edit_find_next"/> <Action name="edit_find_prev"/> <Action name="edit_replace"/> <MergeLocal name="edit_find_merge"/> <Separator/> <MergeLocal/> </Menu> <Menu name="move"><text context="@title:menu Game move">&Move</text> <Action name="move_repeat"/> <Action name="move_undo"/> <Action name="move_redo"/> <MergeLocal name="move_undo_merge"/> <Separator/> <Action name="move_roll"/> <Action name="move_end_turn"/> <MergeLocal name="move_turn_merge"/> <Separator/> <Action name="move_hint"/> <Action name="move_demo"/> <Action name="move_solve"/> <MergeLocal name="move_solve_merge"/> <Separator/> <MergeLocal/> </Menu> <Menu name="view"><text>&View</text> <Action name="view_actual_size"/> <Action name="view_fit_to_page"/> <Action name="view_fit_to_width"/> <Action name="view_fit_to_height"/> <Separator/> <MergeLocal name="view_zoom_merge"/> <Action name="view_zoom_in"/> <Action name="view_zoom_out"/> <Action name="view_zoom"/> <Separator/> <Action name="view_redisplay"/> <Separator/> <MergeLocal/> </Menu> <MergeLocal name="before_go"/> <Menu name="go"><text>&Go</text> <Action name="go_up"/> <Action name="go_back"/> <Action name="go_forward"/> <Action name="go_home"/> <Separator/> <Action name="go_previous"/> <Action name="go_next"/> <Action name="go_goto_page"/> <Action name="go_goto_line"/> <Action name="go_goto"/> <Separator/> <Action name="go_first"/> <Action name="go_last"/> <Separator/> <Action name="go_document_back"/> <Action name="go_document_forward"/> <Separator/> <MergeLocal/> </Menu> <MergeLocal/> <Menu name="bookmarks"><text>&Bookmarks</text> <Action name="bookmark_add"/> <Action name="bookmark_edit"/> <Separator/> <MergeLocal/> </Menu> <Menu name="tools"><text>&Tools</text> <Action name="tools_spelling"/> <MergeLocal/> </Menu> <Menu name="settings"><text>&Settings</text> <MergeLocal/> <Separator/> <Action name="options_show_menubar"/> <Action name="options_show_toolbar"/> <Merge name="StandardToolBarMenuHandler" /> <Merge name="KMDIViewActions"/> <MergeLocal name="show_toolbar_merge"/> <Action name="options_show_statusbar"/> <MergeLocal name="show_merge"/> <Separator/> <Action name="fullscreen"/> <MergeLocal name="fullscreen_merge"/> <Separator/> <Action name="options_save_options"/> <Action name="options_choose_game_type"/> <Action name="options_game_difficulty"/> <MergeLocal name="save_merge"/> <Separator/> <Action name="options_configure_keybinding"/> <Action name="options_configure_toolbars"/> <Action name="options_configure_notifications"/> <Action name="options_configure_carddecks"/> <Action name="options_configure_highscores"/> <MergeLocal name="configure_merge"/> <Action name="options_configure"/> </Menu> <MergeLocal name="settings_merge"/> <Separator/> <Menu name="help"><text>&Help</text> <Action name="help_contents"/> <Action name="help_whats_this"/> <MergeLocal name="help_whats_this_merge"/> <Separator/> <MergeLocal/> <Action name="help_show_tip"/> <Separator/> <Action name="help_report_bug"/> <Separator/> <Action name="help_donate"/> <Separator/> <Action name="switch_application_language"/> <Separator/> <MergeLocal name="about_merge"/> <Action name="help_about_app"/> <Action name="help_about_kde"/> </Menu> </MenuBar> <ToolBar name="mainToolBar"><text>Main Toolbar</text> <Action name="file_new"/> <Action name="file_open"/> <Action name="file_save"/> <Action name="file_print"/> <Action name="file_print_preview"/> <Action name="file_mail"/> <Separator/> <Action name="edit_undo"/> <Action name="edit_redo"/> <Action name="edit_cut"/> <Action name="edit_copy"/> <Action name="edit_paste"/> <Separator/> <Action name="edit_find"/> <Action name="view_zoom"/> <Separator/> <Action name="go_previous"/> <Action name="go_next"/> <Action name="go_home"/> <Separator/> <MergeLocal/> <Action name="help"/> </ToolBar> <StatusBar/> -</kpartgui> +</gui> diff --git a/tests/krichtexteditor/krichtexteditorui.rc b/tests/krichtexteditor/krichtexteditorui.rc index ecd8f32..52d64bf 100644 --- a/tests/krichtexteditor/krichtexteditorui.rc +++ b/tests/krichtexteditor/krichtexteditorui.rc @@ -1,62 +1,62 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="krichtexteditor" version="13"> +<gui name="krichtexteditor" version="13"> <MenuBar> <Menu noMerge="1" name="format"><text>F&ormat</text> <Action name="format_text_bold"/> <Action name="format_text_italic"/> <Action name="format_text_underline"/> <Action name="format_text_strikeout"/> <Action name="format_text_foreground_color"/> <Action name="format_text_background_color"/> <Action name="format_text_superscript"/> <Action name="format_text_subscript"/> <Separator/> <Menu name="alignment"><text>&Alignment</text> <Action name="format_align_left"/> <Action name="format_align_center"/> <Action name="format_align_right"/> <Action name="format_align_justify"/> </Menu> <Separator lineSeparator="true"/> <Action name="format_list_style"/> <Action name="format_list_indent_more"/> <Action name="format_list_indent_less"/> <Separator lineSeparator="true"/> <Action name="insert_horizontal_rule"/> <Action name="manage_link"/> <Action name="format_painter"/> </Menu> </MenuBar> <ToolBar name="textToolBar" iconText="icononly"><text>Text Toolbar</text> <Action name="format_text_bold"/> <Action name="format_text_italic"/> <Action name="format_text_underline"/> <Action name="format_text_strikeout"/> <Action name="format_text_foreground_color"/> <Action name="format_text_background_color"/> <Separator lineSeparator="true"/> <Action name="format_font_family"/> <Action name="format_font_size"/> <Separator lineSeparator="true"/> <Action name="format_text_superscript"/> <Action name="format_text_subscript"/> </ToolBar> <ToolBar name="formatToolBar" iconText="icononly"><text>Format Toolbar</text> <Action name="format_align_left"/> <Action name="format_align_center"/> <Action name="format_align_right"/> <Action name="format_align_justify"/> <Separator lineSeparator="true"/> <Action name="format_list_style"/> <Action name="format_list_indent_more"/> <Action name="format_list_indent_less"/> <Separator lineSeparator="true"/> <Action name="insert_horizontal_rule"/> <Action name="manage_link"/> <Action name="format_painter"/> <Action name="action_to_plain_text"/> </ToolBar> -</kpartgui> +</gui> diff --git a/tests/kwindowtest.rc b/tests/kwindowtest.rc index 10949d1..d86b348 100644 --- a/tests/kwindowtest.rc +++ b/tests/kwindowtest.rc @@ -1,59 +1,59 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="windowtest" version="1"> +<gui name="windowtest" version="1"> <MenuBar> <Menu name="file" noMerge="1"> <text>&File</text> <Action name="filenew" /> <Action name="fileopen" /> <Action name="filefloppy" /> <Action name="fileprint" /> <Separator lineSeparator="true"/> <Action name="exit"/> </Menu> <Menu name="file2"> <text>F&ile2</text> <Action name="filenew2" /> <Action name="fileopen2" /> <Separator /> <Action name="filefloppy2" /> <Action name="fileprint2" /> <Separator /> <Action name="radioButton1" /> <Action name="radioButton2" /> <Action name="radioButton3" /> <Action name="radioButton4" /> </Menu> <Menu name="settings"> <text>&Settings</text> <Merge name="StandardToolBarMenuHandler" append="show_merge"/> </Menu> </MenuBar> <ToolBar name="mainToolBar"><text>Toolbar 1</text> <Action name="filenew" /> <Action name="fileopen" /> <Action name="filefloppy" /> <Action name="fileprint" /> <Action name="combobox" /> <Action name="location" /> <Action name="exit" /> </ToolBar> <ToolBar name="AnotherToolbar"><text>Toolbar 2</text> <Action name="filenew2" /> <Action name="fileopen2" /> <Separator /> <Action name="filefloppy2" /> <Action name="fileprint2" /> <Separator /> <Action name="radioButton1" /> <Action name="radioButton2" /> <Action name="radioButton3" /> <Action name="radioButton4" /> </ToolBar> -</kpartgui> +</gui> diff --git a/tests/kxmlguitest_part.rc b/tests/kxmlguitest_part.rc index 84f5e4f..02b5184 100644 --- a/tests/kxmlguitest_part.rc +++ b/tests/kxmlguitest_part.rc @@ -1,8 +1,8 @@ <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> -<kpartgui name="khtmlpart" version="7"> +<gui name="khtmlpart" version="7"> <ToolBar name="mainToolBar"><text>Main Toolbar</text> <Action name="decFontSizes" /> <Separator /> <Action name="security" /> </ToolBar> -</kpartgui> +</gui> diff --git a/tests/kxmlguitest_shell.rc b/tests/kxmlguitest_shell.rc index e6c3999..b0d8050 100644 --- a/tests/kxmlguitest_shell.rc +++ b/tests/kxmlguitest_shell.rc @@ -1,7 +1,7 @@ -<!DOCTYPE kpartgui ><kpartgui version="31" name="Konqueror" > +<!DOCTYPE kpartgui ><gui version="31" name="Konqueror" > <ToolBar newline="true" name="mainToolBar"> <text>Main Toolbar</text> <Merge/> <Action name="splitviewh" /> </ToolBar> -</kpartgui> +</gui>