Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpavlu committed Mar 12, 2012
1 parent 5a51d83 commit fab96d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
8 changes: 4 additions & 4 deletions cppconsui/ColorScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
* @ingroup cppconsui
*/

/* Uncomment to enable an experimental feature to lower the number of used
* colorpairs */
//#define SAVE_COLOR_PAIRS

#include "ColorScheme.h"

#include "gettext.h"
Expand Down Expand Up @@ -64,7 +60,11 @@ int ColorScheme::GetColorPair(const char *scheme, const char *widget,
return 0;
}

#ifdef SAVE_COLOR_PAIRS
int ColorScheme::GetColorPair(Color& c)
#else
int ColorScheme::GetColorPair(const Color& c)
#endif
{
ColorPairs::const_iterator i;
int fg = c.foreground;
Expand Down
8 changes: 8 additions & 0 deletions cppconsui/ColorScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <map>
#include <string>

/* Uncomment to enable an experimental feature to lower the number of used
* colorpairs. */
//#define SAVE_COLOR_PAIRS

#define COLORSCHEME (CppConsUI::ColorScheme::Instance())

namespace CppConsUI
Expand Down Expand Up @@ -65,7 +69,11 @@ class ColorScheme
*/
int GetColorPair(const char *scheme, const char *widget,
const char *property);
#ifdef SAVE_COLOR_PAIRS
int GetColorPair(Color& c);
#else
int GetColorPair(const Color& c);
#endif
/**
* Sets color pair and Curses attributes for a given scheme, widget,
* property combination.
Expand Down
7 changes: 4 additions & 3 deletions src/CenterIM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ bool CenterIM::SaveColorSchemeConfig()

char *CenterIM::ColorToString(int color)
{
if (color >= -1 && color < (int)G_N_ELEMENTS(named_colors) - 1)
if (color >= -1 && color < static_cast<int>(G_N_ELEMENTS(named_colors) - 1))
return g_strdup(named_colors[color + 1]);
return g_strdup_printf("%d", color);
}
Expand All @@ -742,7 +742,7 @@ bool CenterIM::StringToColor(const char *str, int *color)
*color = 0;

// symbolic colors
for (int i = -1; i < (int)G_N_ELEMENTS(named_colors) - 1; i++)
for (int i = -1; i < static_cast<int>(G_N_ELEMENTS(named_colors) - 1); i++)
if (!strcmp(str, named_colors[i + 1])) {
*color = i;
return true;
Expand Down Expand Up @@ -864,6 +864,7 @@ void CenterIM::LoadDefaultKeyConfig()
KEYCONFIG->BindKey("centerim", "conversation-number17", "Alt-u");
KEYCONFIG->BindKey("centerim", "conversation-number18", "Alt-i");
KEYCONFIG->BindKey("centerim", "conversation-number19", "Alt-o");
KEYCONFIG->BindKey("centerim", "conversation-number20", "Alt-p");

KEYCONFIG->BindKey("buddylist", "contextmenu", "Ctrl-d");

Expand Down Expand Up @@ -1012,7 +1013,7 @@ void CenterIM::DeclareBindables()
sigc::mem_fun(this, &CenterIM::ActionFocusNextConversation),
InputProcessor::BINDABLE_OVERRIDE);
char action[] = "conversation-numberXX";
for (int i = 1; i < 20; i++) {
for (int i = 1; i <= 20; i++) {
g_sprintf(action + sizeof(action) - 3, "%d", i);
DeclareBindable("centerim", action, sigc::bind(sigc::mem_fun(this,
&CenterIM::ActionFocusConversation), i),
Expand Down
37 changes: 15 additions & 22 deletions src/Conversations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,34 @@ void Conversations::FocusActiveConversation()

void Conversations::FocusConversation(int i)
{
int prev, cur;
prev = -1;
cur = NextActiveConversation(prev);

while (cur > prev) {
if (i == 1) {
ActivateConversation(cur);
return;
}
g_assert(i >= 1);

i--;
prev = cur;
cur = NextActiveConversation(cur);
}
if (conversations.empty())
return;

// the external conversation #1 is the internal conversation #0
i -= 1;

// if there is less than i active conversations then active the last one
if (prev != -1)
ActivateConversation(prev);
int s = static_cast<int>(conversations.size());
if (i < s)
ActivateConversation(i);
else {
// if there is less than i active conversations then active the last one
ActivateConversation(s - 1);
}
}

void Conversations::FocusPrevConversation()
{
int i = PrevActiveConversation(active);
if (i == -1)
ActivateConversation(active);
else
if (i != -1)
ActivateConversation(i);
}

void Conversations::FocusNextConversation()
{
int i = NextActiveConversation(active);
if (i == -1)
ActivateConversation(active);
else
if (i != -1)
ActivateConversation(i);
}

Expand Down

0 comments on commit fab96d0

Please sign in to comment.