File indexing completed on 2024-04-21 03:51:10
0001 /* 0002 SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 #include "parleyactions.h" 0006 0007 #include "prefs.h" 0008 0009 #include <KActionCollection> 0010 #include <KLocalizedString> 0011 #include <KStandardAction> 0012 #include <KToggleAction> 0013 0014 #include <QIcon> 0015 0016 namespace ParleyActions 0017 { 0018 namespace Private 0019 { 0020 QAction *createCustomAction(const QObject *recvr, 0021 const char *slot, 0022 QObject *parent, 0023 const QString &name, 0024 const QString &text, 0025 const QString &helpText, 0026 const QString &iconName = QString(), 0027 bool toggle = false) 0028 { 0029 // Create QAction or KToggleAction 0030 QAction *pAction; 0031 if (toggle) { 0032 pAction = new KToggleAction(parent); 0033 } else { 0034 pAction = new QAction(parent); 0035 } 0036 // Set ObjectName, Text and HelpText 0037 pAction->setObjectName(name); 0038 pAction->setText(text); 0039 pAction->setToolTip(helpText); 0040 0041 // Icon 0042 if (!iconName.isEmpty()) { 0043 QIcon foundIcon(QIcon::fromTheme(iconName)); 0044 if (foundIcon.isNull()) { 0045 // Note: If you are using an alternative /usr/share/icons directory you need to 0046 // copy the /usr/share/icons/<theme>/index.theme into you alternate directory 0047 qDebug() << "Missing QIcon " << iconName; 0048 } 0049 pAction->setIcon(foundIcon); 0050 } 0051 0052 // Connect the action 0053 pAction->connect(pAction, SIGNAL(triggered(bool)), recvr, slot); 0054 0055 // If parent is a KActionCollection, add the new action to it 0056 KActionCollection *collection = qobject_cast<KActionCollection *>(parent); 0057 if (pAction && collection) 0058 collection->addAction(pAction->objectName(), pAction); 0059 return pAction; 0060 } 0061 } 0062 } 0063 0064 QAction *ParleyActions::create(ParleyAction id, const QObject *recvr, const char *slot, KActionCollection *parent) 0065 { 0066 QAction *pAction = nullptr; 0067 0068 switch (id) { 0069 case FileNew: 0070 pAction = KStandardAction::openNew(recvr, slot, parent); 0071 pAction->setToolTip(i18n("Creates a new vocabulary collection")); 0072 parent->setDefaultShortcut(pAction, QKeySequence::New); 0073 break; 0074 case FileOpen: 0075 pAction = KStandardAction::open(recvr, slot, parent); 0076 pAction->setToolTip(i18n("Opens an existing vocabulary collection")); 0077 parent->setDefaultShortcut(pAction, QKeySequence::Open); 0078 break; 0079 case FileOpenDownloaded: 0080 pAction = Private::createCustomAction(recvr, 0081 slot, 0082 parent, 0083 QStringLiteral("file_open_downloaded"), 0084 i18n("Open &Downloaded Vocabularies..."), 0085 i18n("Open downloaded vocabulary collections"), 0086 QStringLiteral("get-hot-new-stuff")); 0087 break; 0088 case FileSave: 0089 pAction = KStandardAction::save(recvr, slot, parent); 0090 pAction->setToolTip(i18n("Save the active vocabulary collection")); 0091 parent->setDefaultShortcut(pAction, QKeySequence::Save); 0092 break; 0093 case FileSaveAs: 0094 pAction = KStandardAction::saveAs(recvr, slot, parent); 0095 pAction->setShortcut(QKeySequence::SaveAs); 0096 parent->setDefaultShortcut(pAction, QKeySequence::SaveAs); 0097 pAction->setToolTip(i18n("Save the active vocabulary collection with a different name")); 0098 break; 0099 case FileExport: 0100 pAction = Private::createCustomAction(recvr, 0101 slot, 0102 parent, 0103 QStringLiteral("file_export"), 0104 i18n("&Export..."), 0105 i18n("Export to HTML or CSV"), 0106 QStringLiteral("document-export")); 0107 break; 0108 case FileProperties: 0109 pAction = Private::createCustomAction(recvr, 0110 slot, 0111 parent, 0112 QStringLiteral("file_properties"), 0113 i18n("&Properties..."), 0114 i18n("Edit document properties"), 0115 QStringLiteral("document-properties")); 0116 break; 0117 case FileClose: 0118 pAction = Private::createCustomAction(recvr, 0119 slot, 0120 parent, 0121 QStringLiteral("file_close"), 0122 i18n("Dashboard"), 0123 i18n("Close the current vocabulary collection and show the dashboard"), 0124 QStringLiteral("go-home")); 0125 break; 0126 case FileQuit: 0127 pAction = KStandardAction::quit(recvr, slot, parent); 0128 parent->setDefaultShortcut(pAction, QKeySequence::Quit); 0129 pAction->setToolTip(i18n("Quit Parley")); 0130 break; 0131 case Preferences: 0132 pAction = KStandardAction::preferences(recvr, slot, parent); 0133 parent->setDefaultShortcut(pAction, QKeySequence::Preferences); 0134 pAction->setToolTip(i18n("Show the configuration dialog")); 0135 break; 0136 case LanguagesProperties: 0137 pAction = Private::createCustomAction(recvr, 0138 slot, 0139 parent, 0140 QStringLiteral("edit_languages"), 0141 i18n("&Languages..."), 0142 i18n("Edit which languages are in the collection and their grammar properties."), 0143 QStringLiteral("set-language")); 0144 break; 0145 case RemoveGrades: 0146 pAction = Private::createCustomAction(recvr, 0147 slot, 0148 parent, 0149 QStringLiteral("vocab_remove_grades"), 0150 i18n("Remove Confidence Levels"), 0151 i18n("Remove all confidence levels from the current document"), 0152 QStringLiteral("edit-clear")); 0153 break; 0154 case CheckSpelling: 0155 pAction = KStandardAction::spelling(recvr, slot, parent); 0156 break; 0157 case ToggleShowSublessons: 0158 pAction = Private::createCustomAction(recvr, 0159 slot, 0160 parent, 0161 QStringLiteral("lesson_showsublessonentries"), 0162 i18n("Show Entries from Child Units"), 0163 i18n("Enable to also see the entries of child units in each unit."), 0164 QString(), 0165 true); 0166 pAction->setChecked(Prefs::showSublessonentries()); 0167 break; 0168 case AutomaticTranslation: 0169 pAction = Private::createCustomAction(recvr, 0170 slot, 0171 parent, 0172 QStringLiteral("lesson_automatictranslation"), 0173 i18n("Automatic Translation"), 0174 i18n("Enable automatic translation of the unit entries."), 0175 QString(), 0176 true); 0177 pAction->setChecked(Prefs::automaticTranslation()); 0178 break; 0179 case StartPractice: 0180 pAction = Private::createCustomAction(recvr, 0181 slot, 0182 parent, 0183 QStringLiteral("practice_start"), 0184 i18n("Start Practice..."), 0185 i18n("Start practicing"), 0186 QStringLiteral("practice-start")); 0187 break; 0188 case ConfigurePractice: 0189 pAction = Private::createCustomAction(recvr, 0190 slot, 0191 parent, 0192 QStringLiteral("practice_configure"), 0193 i18n("Configure Practice..."), 0194 i18n("Change practice settings"), 0195 QStringLiteral("practice-setup")); 0196 break; 0197 case ExportPracticeResults: 0198 pAction = Private::createCustomAction(recvr, 0199 slot, 0200 parent, 0201 QStringLiteral("practice_export"), 0202 i18n("Export Results..."), 0203 i18n("Write a file with the results of the practice"), 0204 QStringLiteral("document-export")); 0205 break; 0206 case EnterEditMode: 0207 pAction = Private::createCustomAction(recvr, 0208 slot, 0209 parent, 0210 QStringLiteral("document_edit"), 0211 i18n("Editor"), 0212 i18n("Switch to vocabulary editor"), 0213 QStringLiteral("document-edit")); 0214 break; 0215 case ToggleSearchBar: 0216 pAction = Private::createCustomAction(recvr, 0217 slot, 0218 parent, 0219 QStringLiteral("config_show_search"), 0220 i18n("Show Se&arch"), 0221 i18n("Toggle display of the search bar"), 0222 QString(), 0223 true); 0224 pAction->setChecked(Prefs::showSearch()); 0225 break; 0226 case SearchVocabulary: 0227 pAction = KStandardAction::find(recvr, slot, parent); 0228 parent->setDefaultShortcut(pAction, QKeySequence::Find); 0229 break; 0230 } 0231 0232 Q_ASSERT(pAction); 0233 return pAction; 0234 } 0235 0236 KRecentFilesAction *ParleyActions::createRecentFilesAction(const QObject *recvr, const char *slot, QObject *parent) 0237 { 0238 return KStandardAction::openRecent(recvr, slot, parent); 0239 }