Skip to content

Commit

Permalink
Fix session display when only one session is available
Browse files Browse the repository at this point in the history
  • Loading branch information
sip committed Mar 28, 2007
1 parent 0e0d747 commit 17b17b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
27 changes: 14 additions & 13 deletions cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ using namespace std;

typedef pair<string,string> option;

Cfg::Cfg() {
Cfg::Cfg()
: currentSession(-1)
{
// Configuration options
options.insert(option("default_path","./:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"));
options.insert(option("default_xserver","/usr/X11R6/bin/X"));
Expand Down Expand Up @@ -129,6 +131,7 @@ bool Cfg::readConf(string configfile) {
}
}
cfgfile.close();
split(sessions, getOption("sessions"), ',', false);
return true;
} else {
error = "Cannot read configuration file: " + configfile;
Expand Down Expand Up @@ -220,33 +223,31 @@ int Cfg::absolutepos(const string& position, int max, int width) {
}

// split a comma separated string into a vector of strings
void Cfg::split(vector<string>& v, const string& str, char c) {
void Cfg::split(vector<string>& v, const string& str, char c, bool useEmpty) {
v.clear();
string::const_iterator s = str.begin();
string tmp;
while (true) {
string::const_iterator begin = s;
while (*s != c && s != str.end()) { ++s; }
v.push_back(string(begin, s));
tmp = string(begin, s);
if (useEmpty || tmp.size() > 0)
v.push_back(tmp);
if (s == str.end()) {
break;
}
if (++s == str.end()) {
v.push_back("");
if (useEmpty)
v.push_back("");
break;
}
}
}

string Cfg::nextSession(string current) {
vector<string> sessions;
split(sessions, getOption("sessions"), ',');
if (sessions.size() <= 1)
if (sessions.size() < 1)
return current;

for (int i=0; i<(int)sessions.size()-1; i++) {
if (current == sessions[i]) {
return sessions[i+1];
}
}
return sessions[0];
currentSession = (currentSession + 1) % sessions.size();
return sessions[currentSession];
}
5 changes: 4 additions & 1 deletion cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ class Cfg {

static int absolutepos(const string& position, int max, int width);
static int string2int(const char* string, bool* ok = 0);
static void split(vector<string>& v, const string& str, char c);
static void split(vector<string>& v, const string& str,
char c, bool useEmpty=true);
static string Trim(const string& s);

string nextSession(string current);

private:
map<string,string> options;
vector<string> sessions;
int currentSession;
string error;

};
Expand Down
5 changes: 3 additions & 2 deletions panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ string Panel::getSession() {
// choose next available session type
void Panel::SwitchSession() {
session = cfg->nextSession(session);
//TODO: get sessions from cfg and cycle to the next one
ShowSession();
if (session.size() > 0) {
ShowSession();
}
}

// Display session type on the screen
Expand Down

0 comments on commit 17b17b2

Please sign in to comment.