[kde-doc-english] KDE/kdeedu/khangman/src
Adam Rakowski
foo-script at o2.pl
Wed Jul 14 04:03:54 CEST 2010
SVN commit 1149681 by adamrakowski:
CCMAIL:annma at kde.org
GUI:Recent files support added
M +34 -12 khangman.cpp
M +11 -1 khangman.h
M +1 -1 khangmanui.rc
M +5 -5 khmthemefactory.h
--- trunk/KDE/kdeedu/khangman/src/khangman.cpp #1149680:1149681
@@ -49,12 +49,14 @@
#include <KIcon>
#include <KGlobal>
#include <KSharedConfig>
+#include <KRecentFilesAction>
#include <knewstuff2/engine.h>
KHangMan::KHangMan()
: KXmlGuiWindow(), m_currentLevel(-1),
- m_view(new KHangManView(this))
+ m_view(new KHangManView(this)),
+ m_recent(0)
{
setObjectName(QLatin1String("KHangMan"));
@@ -142,6 +144,12 @@
m_modeAction->setToolTip(i18n( "Choose the look and feel" ));
m_modeAction->setWhatsThis(i18n( "Choose the look and feel" ));
+ config = KGlobal::config();
+
+ m_recent=KStandardAction::openRecent(this, SLOT(slotOpenRecent(const KUrl &)), this);
+ m_recent->setWhatsThis(i18n("You can open last opened files")); //TODO: Check the description
+ actionCollection()->addAction(m_recent->objectName(), m_recent);
+ m_recent->loadEntries(KConfigGroup(config, "KHangManRecent"));
setupGUI();
}
@@ -166,9 +174,10 @@
// Slots
-void KHangMan::slotQuit()
+void KHangMan::slotQuit() //TODO: Isn't called when "X" pressed, only when File->Quit
{
Prefs::setShowCharToolbar( specialCharToolbar->isVisible() );
+ m_recent->saveEntries(KConfigGroup(config, "KHangManRecent"));
Prefs::self()->writeConfig();
qApp->closeAllWindows();
}
@@ -532,6 +541,23 @@
}
}
+void KHangMan::loadFile(const KUrl & url)
+{
+ if ( url.isValid() ) {
+ if(url.isLocalFile())
+ Prefs::setLevelFile(url.toLocalFile());
+ else Prefs::setLevelFile(url.path());
+
+ Prefs::self()->writeConfig();
+ m_recent->addUrl(url);
+ m_recent->saveEntries(KConfigGroup(config, "KHangManRecent"));
+
+ changeStatusbar(url.path().section('/', -1), IDS_LEVEL);
+ m_view->readFile();
+ m_view->newGame();
+ }
+}
+
void KHangMan::slotNewGame()
{
m_view->lossCount++;
@@ -539,20 +565,16 @@
m_view->newGame();
}
+void KHangMan::slotOpenRecent(const KUrl & url)
+{
+ loadFile(url);
+}
+
void KHangMan::slotFileOpen()
{
KUrl url = KFileDialog::getOpenUrl(QString(), KEduVocDocument::pattern(KEduVocDocument::Reading), this, i18n("Open Vocabulary Document"));
- if ( url.isValid() ) {
- if(url.isLocalFile())
- Prefs::setLevelFile(url.toLocalFile());
- else
- Prefs::setLevelFile(url.path());
- Prefs::self()->writeConfig();
- changeStatusbar(url.path().section('/', -1), IDS_LEVEL);
- m_view->readFile();
- m_view->newGame();
+ loadFile(url);
}
-}
void KHangMan::slotSetHint(bool hint)
{
--- trunk/KDE/kdeedu/khangman/src/khangman.h #1149680:1149681
@@ -30,6 +30,7 @@
class KSelectAction;
class KToggleAction;
+class KRecentFilesAction;
// Id tags for the status bar.
@@ -95,6 +96,9 @@
void slotNewGame();
///open a local KVTML file
void slotFileOpen();
+ ///open a user's recent file
+ void slotOpenRecent(const KUrl &);
+
/**
Update the text in the Statusbar
@param text the text that will be written in the statusbar
@@ -116,7 +120,8 @@
void loadLevels();
///Set a bool variable to true if the language allowa accented letters to be displayed with corresponding letter
void setAccent();
-
+ ///Loads a file in URL, or displays file open dialog if argument is empty
+ void loadFile(const KUrl &);
// Populate the second toolbar with the correct buttons if the
// current language has special characters.
void loadLangToolBar();
@@ -158,6 +163,11 @@
//Theme manager
KHMThemeFactory khm_factory;
+
+ //Config group
+ KSharedConfig::Ptr config;
+ //Recent files element
+ KRecentFilesAction * m_recent;
};
#endif // _KHANGMAN_H_
--- trunk/KDE/kdeedu/khangman/src/khangmanui.rc #1149680:1149681
@@ -5,11 +5,11 @@
<Menu name="file" noMerge="1"><text>&Game</text>
<Action name="file_new"/>
<Action name="file_open"/>
+ <Action name="file_open_recent" />
<Action name="downloadnewstuff"/>
<Separator/>
<Action name="file_quit"/>
</Menu>
-
<Action name="combo_level"/>
<Action name="languages"/>
--- trunk/KDE/kdeedu/khangman/src/khmthemefactory.h #1149680:1149681
@@ -38,12 +38,12 @@
~KHMThemeFactory();
bool addTheme(QString filePath); //returns "true" if theme has been added successfuly, "false" otherwise
- void walkDirectory(QDir dir);
+ void walkDirectory(QDir dir); //walks the directory loads valid themes files. No recursion
- int getQty() const;
- QStringList getNames();
- QStringList themeList();
- KHMTheme * buildTheme(int id); //theme at index "index" must exists
+ int getQty() const; //returns quantity of list
+ QStringList getNames(); //returns short names(worknames) of all the themes
+ QStringList themeList(); //returns user interface names of all the themes
+ KHMTheme * buildTheme(int id); //Returns theme at "index". An "index" must exists
private:
QList<KHMTheme> themesList;
More information about the kde-doc-english
mailing list