src/tron/gServerFavorites.cpp File Reference

#include "rSDL.h"
#include "gServerFavorites.h"
#include "gLogo.h"
#include "gGame.h"
#include "uMenu.h"
#include "tConfiguration.h"
#include "tDirectories.h"
#include "gServerBrowser.h"
#include "nServerInfo.h"
#include <sstream>

Include dependency graph for gServerFavorites.cpp:

Go to the source code of this file.

Classes

class  gServerFavorite
 server favorite: holds connection info and configuration items More...
class  gServerFavoritesHolder
 server favorites management class: holds an array of servers More...
class  gMenuItemEditSubmenu
 edit submenu item quitting the parent menu when it's done More...
class  gCustomConnectEntries
 conglomerate of menus and entries for custom connect More...
class  gServerFavoriteMenuEntries
 conglomerate of menus and entries More...

Typedefs

typedef nServerInfoRedirect gServerInfoFavorite

Enumerations

enum  { NUM_FAVORITES = 10 }

Functions

static tString sg_ConfName (int ID, char const *prefix, char const *name)
static void sg_ConnectFavorite (int ID)
 connect to a favorite server
static void sg_AlternativeMaster (int ID)
 browse servers on alternative master server
static void sg_AddBookmarkString (char const *suffix, tOutput &addTo)
static tOutput sg_GetBookmarkString (char const *suffix)
static void sg_GenerateConnectionItems ()
static void sg_EditServers ()
static void sg_ClearConnectionItems ()
static void sg_TransferCustomServer ()
 transfer old custom server name to favorite
static void sg_FavoritesMenu (INTFUNCPTR connect, gServerFavoritesHolder &holder, int lowPort)

Variables

static gServerFavoritesHolder sg_favoriteHolder ("")
static gServerFavoritesHolder sg_masterHolder ("_MASTER")
static INTFUNCPTR sg_Connect = &sg_ConnectFavorite
static gServerFavoritesHoldersg_holder = &sg_favoriteHolder
static int sg_lowPort = gServerBrowser::lowPort
static char * sg_languageIDPrefix = "$bookmarks_"
static uMenusg_connectionMenu = 0
static uMenuItemsg_connectionMenuItemKeep = 0
static tString sg_customServerName ("")
 TODO for 3.0 or 3.1: phase out this legacy support.
static tConfItemLine sg_serverName_ci ("CUSTOM_SERVER_NAME", sg_customServerName)
static int sg_clientPort = 4534
static tConfItem< int > sg_cport ("CLIENT_PORT", sg_clientPort)


Typedef Documentation

typedef nServerInfoRedirect gServerInfoFavorite

Definition at line 60 of file gServerFavorites.cpp.


Enumeration Type Documentation

anonymous enum

Enumerator:
NUM_FAVORITES 

Definition at line 49 of file gServerFavorites.cpp.

00049 { NUM_FAVORITES = 10 };


Function Documentation

static void sg_AddBookmarkString ( char const *  suffix,
tOutput addTo 
) [static]

Definition at line 254 of file gServerFavorites.cpp.

References sg_languageIDPrefix.

Referenced by gServerFavoriteMenuEntries::gServerFavoriteMenuEntries(), sg_GenerateConnectionItems(), and sg_GetBookmarkString().

00255 {
00256     std::ostringstream s;
00257     s << sg_languageIDPrefix;
00258     s << suffix;
00259     addTo << s.str().c_str();
00260 }

Here is the caller graph for this function:

static void sg_AlternativeMaster ( int  ID  )  [static]

browse servers on alternative master server

Definition at line 229 of file gServerFavorites.cpp.

References gServerFavorite::address_, gServerBrowser::BrowseSpecialMaster(), gServerFavoritesHolder::GetFavorite(), gServerFavorite::port_, and sg_masterHolder.

Referenced by gServerFavorites::AlternativesMenu().

00230 {
00231     // generate suffix for filename
00232     std::stringstream suffix;
00233     suffix << "_" << ID;
00234 
00235     // fetch server info
00236     gServerFavorite & favorite = sg_masterHolder.GetFavorite(ID);
00237     gServerInfoFavorite fav( favorite.address_, favorite.port_ );
00238 
00239     // browse master info
00240     gServerBrowser::BrowseSpecialMaster( &fav, suffix.str().c_str() );
00241 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sg_ClearConnectionItems (  )  [static]

Definition at line 368 of file gServerFavorites.cpp.

References uMenu::Item(), uMenu::NumItems(), and tASSERT.

Referenced by sg_FavoritesMenu(), and sg_GenerateConnectionItems().

00369 {
00370     tASSERT( sg_connectionMenu );
00371 
00372     // delete old connection items
00373     for ( int i = sg_connectionMenu->NumItems()-1; i>=0; --i )
00374     {
00375         uMenuItem * item = sg_connectionMenu->Item(i);
00376         if ( item != sg_connectionMenuItemKeep )
00377             delete item;
00378     }
00379 }

Here is the call graph for this function:

Here is the caller graph for this function:

static tString sg_ConfName ( int  ID,
char const *  prefix,
char const *  name 
) [static]

Definition at line 65 of file gServerFavorites.cpp.

00066 {
00067     std::stringstream s;
00068     s << "BOOKMARK_" << prefix << ID+1 << name;
00069 
00070     return tString( s.str().c_str() );
00071 }

static void sg_ConnectFavorite ( int  ID  )  [static]

connect to a favorite server

Definition at line 223 of file gServerFavorites.cpp.

References gServerFavorite::Connect(), gServerFavoritesHolder::GetFavorite(), and sg_favoriteHolder.

Referenced by gServerFavorites::FavoritesMenu().

00224 {
00225     sg_favoriteHolder.GetFavorite(ID).Connect();
00226 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sg_EditServers (  )  [static]

Definition at line 342 of file gServerFavorites.cpp.

References uMenu::Enter(), gServerFavoritesHolder::GetFavorite(), NUM_FAVORITES, sg_GenerateConnectionItems(), sg_GetBookmarkString(), and tNEW.

Referenced by sg_FavoritesMenu().

00343 {
00344     int i;
00345 
00346     // create menu
00347     uMenu edit_menu(sg_GetBookmarkString( "menu_edit" ) );
00348 
00349     // create menu entries
00350     gServerFavoriteMenuEntries * entries[ NUM_FAVORITES ];
00351     for ( i = NUM_FAVORITES-1; i>=0; --i )
00352         entries[i] = tNEW( gServerFavoriteMenuEntries )( sg_holder->GetFavorite(i), edit_menu );
00353 
00354     // enter menu
00355     edit_menu.Enter();
00356 
00357     // delete menu entries
00358     for ( i = NUM_FAVORITES-1; i>=0; --i )
00359         delete entries[i];
00360 
00361     // regenerate parent menu
00362     sg_GenerateConnectionItems();
00363 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sg_FavoritesMenu ( INTFUNCPTR  connect,
gServerFavoritesHolder holder,
int  lowPort 
) [static]

Definition at line 423 of file gServerFavorites.cpp.

References uMenu::Enter(), NULL, sg_ClearConnectionItems(), sg_Connect, sg_EditServers(), sg_GenerateConnectionItems(), sg_GetBookmarkString(), sg_lowPort, and sg_TransferCustomServer().

Referenced by gServerFavorites::AlternativesMenu(), and gServerFavorites::FavoritesMenu().

00424 {
00425     sg_Connect = connect;
00426     sg_holder  = &holder;
00427     sg_lowPort = lowPort;
00428 
00429     sg_TransferCustomServer();
00430 
00431     uMenu net_menu(sg_GetBookmarkString( "menu" ) );
00432     sg_connectionMenu = & net_menu;
00433 
00434     uMenuItemFunction edit(&net_menu,sg_GetBookmarkString( "menu_edit" ), sg_GetBookmarkString( "menu_edit_help" ),&sg_EditServers);
00435     sg_connectionMenuItemKeep = & edit;
00436 
00437     sg_GenerateConnectionItems();
00438     net_menu.Enter();
00439     sg_ClearConnectionItems();
00440 
00441     sg_connectionMenuItemKeep = NULL;
00442     sg_connectionMenu = NULL;
00443 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sg_GenerateConnectionItems (  )  [static]

Definition at line 380 of file gServerFavorites.cpp.

References gServerFavorite::address_, gServerFavoritesHolder::GetFavorite(), gServerFavorite::name_, NUM_FAVORITES, tOutput::SetTemplateParameter(), sg_AddBookmarkString(), sg_ClearConnectionItems(), sg_Connect, sg_GetBookmarkString(), tASSERT, and tNEW.

Referenced by sg_EditServers(), and sg_FavoritesMenu().

00381 {
00382     tASSERT( sg_connectionMenu );
00383 
00384     // delete old connection items
00385     sg_ClearConnectionItems();
00386 
00387     // create new connection items
00388     for ( int i = NUM_FAVORITES-1; i>=0; --i )
00389     {
00390         gServerFavorite & fav = sg_holder->GetFavorite(i);
00391 
00392         if (fav.name_ != "" && fav.name_ != "Empty" && fav.address_ != "")
00393         {
00394             tOutput fc;
00395             fc.SetTemplateParameter(1,tColoredString::RemoveColors(fav.name_) );
00396             sg_AddBookmarkString( "menu_connect", fc );
00397 
00398             tNEW(uMenuItemFunctionInt)(sg_connectionMenu ,fc ,sg_GetBookmarkString( "menu_edit_connect_help" ) , sg_Connect, i );
00399         }
00400     }
00401 }

Here is the call graph for this function:

Here is the caller graph for this function:

static tOutput sg_GetBookmarkString ( char const *  suffix  )  [static]

Definition at line 263 of file gServerFavorites.cpp.

References sg_AddBookmarkString().

Referenced by gCustomConnectEntries::Generate(), gServerFavoriteMenuEntries::gServerFavoriteMenuEntries(), sg_EditServers(), sg_FavoritesMenu(), and sg_GenerateConnectionItems().

00264 {
00265     tOutput ret;
00266     sg_AddBookmarkString( suffix, ret );
00267     return ret;
00268 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void sg_TransferCustomServer (  )  [static]

transfer old custom server name to favorite

Definition at line 410 of file gServerFavorites.cpp.

References gServerFavorites::AddFavorite(), server(), sg_clientPort, and sg_customServerName.

Referenced by gServerFavorites::CustomConnectMenu(), and sg_FavoritesMenu().

00411 {
00412     if ( sg_customServerName != "" )
00413     {
00414         // add custom connect server to favorites
00415         gServerInfoFavorite server( sg_customServerName, sg_clientPort );
00416         gServerFavorites::AddFavorite( &server );
00417 
00418         // clear custom connect server
00419         sg_customServerName = "";
00420     }
00421 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int sg_clientPort = 4534 [static]

Definition at line 406 of file gServerFavorites.cpp.

Referenced by sg_TransferCustomServer().

INTFUNCPTR sg_Connect = &sg_ConnectFavorite [static]

Definition at line 244 of file gServerFavorites.cpp.

Referenced by gCustomConnectEntries::Generate(), sg_FavoritesMenu(), and sg_GenerateConnectionItems().

uMenu* sg_connectionMenu = 0 [static]

Definition at line 366 of file gServerFavorites.cpp.

uMenuItem* sg_connectionMenuItemKeep = 0 [static]

Definition at line 367 of file gServerFavorites.cpp.

tConfItem<int> sg_cport("CLIENT_PORT", sg_clientPort) [static]

tString sg_customServerName("") [static]

TODO for 3.0 or 3.1: phase out this legacy support.

Referenced by sg_TransferCustomServer().

gServerFavoritesHolder sg_favoriteHolder("") [static]

Referenced by gServerFavorites::AddFavorite(), gServerFavorites::CustomConnectMenu(), gServerFavorites::FavoritesMenu(), gServerFavorites::IsFavorite(), and sg_ConnectFavorite().

gServerFavoritesHolder* sg_holder = &sg_favoriteHolder [static]

Definition at line 246 of file gServerFavorites.cpp.

char* sg_languageIDPrefix = "$bookmarks_" [static]

Definition at line 250 of file gServerFavorites.cpp.

Referenced by gServerFavorites::AlternativesMenu(), gServerFavorites::FavoritesMenu(), and sg_AddBookmarkString().

int sg_lowPort = gServerBrowser::lowPort [static]

Definition at line 248 of file gServerFavorites.cpp.

Referenced by gCustomConnectEntries::Generate(), and sg_FavoritesMenu().

gServerFavoritesHolder sg_masterHolder("_MASTER") [static]

Referenced by gServerFavorites::AlternativesMenu(), and sg_AlternativeMaster().

tConfItemLine sg_serverName_ci("CUSTOM_SERVER_NAME", sg_customServerName) [static]


Generated on Sat Mar 15 23:18:02 2008 for Armagetron Advanced by  doxygen 1.5.4