00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kstdgameaction.h"
00021
00022 #include <tdelocale.h>
00023 #include <tdeaction.h>
00024 #include <tdestdaccel.h>
00025 #include <tdeconfig.h>
00026 #include <kdebug.h>
00027
00028
00029 KStdGameAction::KStdGameAction()
00030 {}
00031
00032 KStdGameAction::~KStdGameAction()
00033 {}
00034
00035 TDEAction *KStdGameAction::action(StdGameAction act_enum, const TQObject *recvr,
00036 const char *slot, TDEActionCollection *parent,
00037 const char *name)
00038 {
00039 return create( act_enum, name, recvr, slot, parent );
00040 }
00041
00042 const char* KStdGameAction::stdName(StdGameAction act_enum)
00043 {
00044 return name(act_enum);
00045 }
00046
00047 struct KStdGameActionInfo
00048 {
00049 KStdGameAction::StdGameAction id;
00050 TDEStdAccel::StdAccel globalAccel;
00051 int shortcut;
00052 const char* psName;
00053 const char* psLabel;
00054 const char* psWhatsThis;
00055 const char* psIconName;
00056 };
00057
00058 const KStdGameActionInfo g_rgActionInfo[] = {
00059
00060 { KStdGameAction::New, TDEStdAccel::New, 0, "game_new", I18N_NOOP2("new game", "&New"), 0, "document-new" },
00061 { KStdGameAction::Load, TDEStdAccel::Open, 0, "game_load", I18N_NOOP("&Load..."), 0, "document-open" },
00062 { KStdGameAction::LoadRecent, TDEStdAccel::AccelNone, 0, "game_load_recent", I18N_NOOP("Load &Recent"), 0, 0 },
00063 { KStdGameAction::Restart, TDEStdAccel::Reload, 0, "game_restart", I18N_NOOP("Restart &Game"), 0, "reload" },
00064 { KStdGameAction::Save, TDEStdAccel::Save, 0, "game_save", I18N_NOOP("&Save"), 0, "document-save" },
00065 { KStdGameAction::SaveAs, TDEStdAccel::AccelNone, 0, "game_save_as", I18N_NOOP("Save &As..."), 0, "document-save-as" },
00066 { KStdGameAction::End, TDEStdAccel::End, 0, "game_end", I18N_NOOP("&End Game"), 0, "window-close" },
00067 { KStdGameAction::Pause, TDEStdAccel::AccelNone, TQt::Key_P, "game_pause", I18N_NOOP("Pa&use"), 0, "media-playback-pause" },
00068 { KStdGameAction::Highscores, TDEStdAccel::AccelNone, TQt::CTRL+TQt::Key_H, "game_highscores", I18N_NOOP("Show &Highscores"), 0, "highscore" },
00069 { KStdGameAction::Print, TDEStdAccel::Print, 0, "game_print", I18N_NOOP("&Print..."), 0, "document-print" },
00070 { KStdGameAction::Quit, TDEStdAccel::Quit, 0, "game_quit", I18N_NOOP("&Quit"), 0, "exit" },
00071
00072 { KStdGameAction::Repeat, TDEStdAccel::AccelNone, 0, "move_repeat", I18N_NOOP("Repeat"), 0, 0 },
00073 { KStdGameAction::Undo, TDEStdAccel::Undo, 0, "move_undo", I18N_NOOP("Und&o"), 0, "undo" },
00074 { KStdGameAction::Redo, TDEStdAccel::Redo, 0, "move_redo", I18N_NOOP("Re&do"), 0, "redo" },
00075 { KStdGameAction::Roll, TDEStdAccel::AccelNone, TQt::CTRL+TQt::Key_R, "move_roll", I18N_NOOP("&Roll Dice"), 0, "roll" },
00076 { KStdGameAction::EndTurn, TDEStdAccel::AccelNone, 0, "move_end_turn", I18N_NOOP("End Turn"), 0, "endturn" },
00077 { KStdGameAction::Hint, TDEStdAccel::AccelNone, TQt::Key_H, "move_hint", I18N_NOOP("&Hint"), 0, "idea" },
00078 { KStdGameAction::Demo, TDEStdAccel::AccelNone, TQt::Key_D, "move_demo", I18N_NOOP("&Demo"), 0, "1rightarrow" },
00079 { KStdGameAction::Solve, TDEStdAccel::AccelNone, 0, "move_solve", I18N_NOOP("&Solve"), 0, "wizard" },
00080
00081 { KStdGameAction::ChooseGameType, TDEStdAccel::AccelNone, 0, "options_choose_game_type", I18N_NOOP("Choose Game &Type"), 0, 0 },
00082 { KStdGameAction::Carddecks, TDEStdAccel::AccelNone, 0, "options_configure_carddecks", I18N_NOOP("Configure &Carddecks..."), 0, 0 },
00083 { KStdGameAction::ConfigureHighscores, TDEStdAccel::AccelNone, 0, "options_configure_highscores", I18N_NOOP("Configure &Highscores..."), 0, 0 },
00084
00085 { KStdGameAction::ActionNone, TDEStdAccel::AccelNone, 0, 0, 0, 0, 0 }
00086 };
00087
00088 static const KStdGameActionInfo* infoPtr( KStdGameAction::StdGameAction id )
00089 {
00090 for (uint i = 0; g_rgActionInfo[i].id!=KStdGameAction::ActionNone; i++) {
00091 if( g_rgActionInfo[i].id == id )
00092 return &g_rgActionInfo[i];
00093 }
00094 return 0;
00095 }
00096
00097
00098 TDEAction* KStdGameAction::create(StdGameAction id, const char *name,
00099 const TQObject *recvr, const char *slot,
00100 TDEActionCollection* parent )
00101 {
00102 TDEAction* pAction = 0;
00103 const KStdGameActionInfo* pInfo = infoPtr( id );
00104 kdDebug(125) << "KStdGameAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl;
00105 if( pInfo ) {
00106 TQString sLabel = i18n(pInfo->psLabel);
00107 TDEShortcut cut = (pInfo->globalAccel==TDEStdAccel::AccelNone
00108 ? TDEShortcut(pInfo->shortcut)
00109 : TDEStdAccel::shortcut(pInfo->globalAccel));
00110 const char *n = name ? name : pInfo->psName;
00111 switch( id ) {
00112 case LoadRecent:
00113 pAction =
00114 new TDERecentFilesAction(sLabel, cut, recvr, slot, parent, n);
00115 break;
00116 case Pause:
00117 case Demo:
00118 pAction = new TDEToggleAction( sLabel, pInfo->psIconName, cut,
00119 recvr, slot, parent, n);
00120 break;
00121 case ChooseGameType:
00122 pAction = new TDESelectAction( sLabel, pInfo->psIconName, cut,
00123 recvr, slot, parent, n);
00124 break;
00125 default:
00126 pAction = new TDEAction( sLabel, pInfo->psIconName, cut,
00127 recvr, slot, parent, n);
00128 break;
00129 }
00130 }
00131 return pAction;
00132 }
00133
00134 const char* KStdGameAction::name( StdGameAction id )
00135 {
00136 const KStdGameActionInfo* pInfo = infoPtr( id );
00137 return (pInfo) ? pInfo->psName : 0;
00138 }
00139
00140 TDEAction *KStdGameAction::gameNew(const TQObject *recvr, const char *slot,
00141 TDEActionCollection *parent, const char *name )
00142 { return KStdGameAction::create(New, name, recvr, slot, parent); }
00143 TDEAction *KStdGameAction::load(const TQObject *recvr, const char *slot,
00144 TDEActionCollection *parent, const char *name )
00145 { return KStdGameAction::create(Load, name, recvr, slot, parent); }
00146 TDERecentFilesAction *KStdGameAction::loadRecent(const TQObject *recvr, const char *slot,
00147 TDEActionCollection *parent, const char *name )
00148 { return static_cast<TDERecentFilesAction *>(KStdGameAction::create(LoadRecent, name, recvr, slot, parent)); }
00149 TDEAction *KStdGameAction::save(const TQObject *recvr, const char *slot,
00150 TDEActionCollection *parent, const char *name )
00151 { return KStdGameAction::create(Save, name, recvr, slot, parent); }
00152 TDEAction *KStdGameAction::saveAs(const TQObject *recvr, const char *slot,
00153 TDEActionCollection *parent, const char *name )
00154 { return KStdGameAction::create(SaveAs, name, recvr, slot, parent); }
00155 TDEAction *KStdGameAction::end(const TQObject *recvr, const char *slot,
00156 TDEActionCollection *parent, const char *name )
00157 { return KStdGameAction::create(End, name, recvr, slot, parent); }
00158 TDEToggleAction *KStdGameAction::pause(const TQObject *recvr, const char *slot,
00159 TDEActionCollection *parent, const char *name )
00160 { return static_cast<TDEToggleAction *>(KStdGameAction::create(Pause, name, recvr, slot, parent)); }
00161 TDEAction *KStdGameAction::highscores(const TQObject *recvr, const char *slot,
00162 TDEActionCollection *parent, const char *name )
00163 { return KStdGameAction::create(Highscores, name, recvr, slot, parent); }
00164 TDEAction *KStdGameAction::print(const TQObject *recvr, const char *slot,
00165 TDEActionCollection *parent, const char *name )
00166 { return KStdGameAction::create(Print, name, recvr, slot, parent); }
00167 TDEAction *KStdGameAction::quit(const TQObject *recvr, const char *slot,
00168 TDEActionCollection *parent, const char *name )
00169 { return KStdGameAction::create(Quit, name, recvr, slot, parent); }
00170
00171 TDEAction *KStdGameAction::repeat(const TQObject *recvr, const char *slot,
00172 TDEActionCollection *parent, const char *name )
00173 { return KStdGameAction::create(Repeat, name, recvr, slot, parent); }
00174 TDEAction *KStdGameAction::undo(const TQObject *recvr, const char *slot,
00175 TDEActionCollection *parent, const char *name )
00176 { return KStdGameAction::create(Undo, name, recvr, slot, parent); }
00177
00178 TDEAction *KStdGameAction::redo(const TQObject *recvr, const char *slot,
00179 TDEActionCollection *parent, const char *name )
00180 { return KStdGameAction::create(Redo, name, recvr, slot, parent); }
00181
00182 TDEAction *KStdGameAction::roll(const TQObject *recvr, const char *slot,
00183 TDEActionCollection *parent, const char *name )
00184 { return KStdGameAction::create(Roll, name, recvr, slot, parent); }
00185 TDEAction *KStdGameAction::endTurn(const TQObject *recvr, const char *slot,
00186 TDEActionCollection *parent, const char *name )
00187 { return KStdGameAction::create(EndTurn, name, recvr, slot, parent); }
00188
00189 TDEAction *KStdGameAction::carddecks(const TQObject *recvr, const char *slot,
00190 TDEActionCollection *parent, const char *name )
00191 { return KStdGameAction::create(Carddecks, name, recvr, slot, parent); }
00192 TDEAction *KStdGameAction::configureHighscores(const TQObject*recvr, const char *slot,
00193 TDEActionCollection *parent, const char *name)
00194 { return KStdGameAction::create(ConfigureHighscores, name, recvr, slot, parent); }
00195 TDEAction *KStdGameAction::hint(const TQObject*recvr, const char *slot,
00196 TDEActionCollection *parent, const char *name)
00197 { return KStdGameAction::create(Hint, name, recvr, slot, parent); }
00198 TDEToggleAction *KStdGameAction::demo(const TQObject*recvr, const char *slot,
00199 TDEActionCollection *parent, const char *name)
00200 { return static_cast<TDEToggleAction *>(KStdGameAction::create(Demo, name, recvr, slot, parent)); }
00201 TDEAction *KStdGameAction::solve(const TQObject*recvr, const char *slot,
00202 TDEActionCollection *parent, const char *name)
00203 { return KStdGameAction::create(Solve, name, recvr, slot, parent); }
00204 TDESelectAction *KStdGameAction::chooseGameType(const TQObject*recvr, const char *slot,
00205 TDEActionCollection *parent, const char *name)
00206 { return static_cast<TDESelectAction *>(KStdGameAction::create(ChooseGameType, name, recvr, slot, parent)); }
00207 TDEAction *KStdGameAction::restart(const TQObject*recvr, const char *slot,
00208 TDEActionCollection *parent, const char *name)
00209 { return KStdGameAction::create(Restart, name, recvr, slot, parent); }