/* Klat - A LaTeX editor for KDE Copyright (C) 2002-2004 Jori Liesenborgs (jori@lumumba.luc.ac.be) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "klatexecconfig.h" #include KlatExecConfig::KlatExecConfig() { it = execEntries.end(); } KlatExecConfig::~KlatExecConfig() { } #define EXECMENUNAME "ExecutionMenu" #define KEYNAME "Item_" #define SAVEFILEYES "yes" #define SAVEFILENO "no" void KlatExecConfig::read(KConfig *cfg) { int count; bool done; cfg->setGroup(EXECMENUNAME); execEntries.clear(); count = 0; done = false; while (!done) { QString key = KEYNAME + QString::number(count); if (!cfg->hasKey(key)) done = true; else { QStringList lst = cfg->readListEntry(key); if (!lst.empty()) { QStringList::const_iterator i; QString menuname,cmdline; bool save = false; KShortcut shortcut; i = lst.begin(); menuname = (*i); i++; if (i != lst.end()) { cmdline = (*i); i++; if (i != lst.end()) { if ((*i) == QString(SAVEFILEYES)) save = true; i++; if (i != lst.end()) shortcut = KShortcut(*i); } } execEntries.push_back(KlatExecMenuEntry(menuname,cmdline,save,shortcut)); } } count++; } it = execEntries.end(); } void KlatExecConfig::write(KConfig *cfg) { std::list::const_iterator i; int count; cfg->deleteGroup(EXECMENUNAME); cfg->setGroup(EXECMENUNAME); for (i = execEntries.begin(),count = 0 ; i != execEntries.end() ; ++i,count++) { QString key = KEYNAME + QString::number(count); QStringList lst; lst.push_back((*i).menuName()); lst.push_back((*i).commandLine()); if ((*i).saveFirst()) lst.push_back(QString(SAVEFILEYES)); else lst.push_back(QString(SAVEFILENO)); lst.push_back((*i).shortcut().toString()); cfg->writeEntry(key,lst); } cfg->sync(); } bool KlatExecConfig::gotoFirstEntry() { if (execEntries.empty()) return false; it = execEntries.begin(); return true; } bool KlatExecConfig::gotoNextEntry() { if (execEntries.empty()) return false; if (it == execEntries.end()) return false; it++; if (it == execEntries.end()) return false; return true; } bool KlatExecConfig::gotoEntry(int index) { if (execEntries.empty()) return false; if (index < 0) // make sure no item is selected { it = execEntries.end(); return true; } int i = 0; it = execEntries.begin(); while (i < index) { it++; i++; if (it == execEntries.end()) return false; } return true; } QString KlatExecConfig::menuName() { if (execEntries.empty()) return QString(""); if (it == execEntries.end()) return QString(""); return (*it).menuName(); } QString KlatExecConfig::commandLine() { if (execEntries.empty()) return QString(""); if (it == execEntries.end()) return QString(""); return (*it).commandLine(); } bool KlatExecConfig::saveFirst() { if (execEntries.empty()) return false; if (it == execEntries.end()) return false; return (*it).saveFirst(); } KShortcut KlatExecConfig::shortcut() { KShortcut c; if (execEntries.empty()) return c; if (it == execEntries.end()) return c; c = (*it).shortcut(); return c; } KlatExecMenuEntry KlatExecConfig::entry() { KlatExecMenuEntry e("","",false,KShortcut()); if (execEntries.empty()) return e; if (it == execEntries.end()) return e; return (*it); } void KlatExecConfig::insertAfterCurrent(const KlatExecMenuEntry &entry) { if (execEntries.empty() || it == execEntries.end()) { execEntries.push_front(entry); it = execEntries.begin(); } else { it++; it = execEntries.insert(it,entry); } } void KlatExecConfig::deleteCurrent() { if (execEntries.empty()) return; if (it == execEntries.end()) return; execEntries.erase(it); it = execEntries.end(); } void KlatExecConfig::changeCurrent(const KlatExecMenuEntry &m) { if (execEntries.empty()) return; if (it == execEntries.end()) return; (*it) = m; }