@@ -5297,217 +5297,67 @@ cmd_wrap(ProfWin* window, const char* const command, gchar** args)
52975297gboolean
52985298cmd_time (ProfWin * window , const char * const command , gchar * * args )
52995299{
5300- if (g_strcmp0 (args [0 ], "lastactivity" ) == 0 ) {
5301- if (args [1 ] == NULL ) {
5302- auto_gchar gchar * format = prefs_get_string (PREF_TIME_LASTACTIVITY );
5303- cons_show ("Last activity time format: '%s'." , format );
5304- return TRUE;
5305- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5306- prefs_set_string (PREF_TIME_LASTACTIVITY , args [2 ]);
5307- cons_show ("Last activity time format set to '%s'." , args [2 ]);
5308- ui_redraw ();
5309- return TRUE;
5310- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5311- cons_show ("Last activity time cannot be disabled." );
5312- ui_redraw ();
5313- return TRUE;
5314- } else {
5315- cons_bad_cmd_usage (command );
5316- return TRUE;
5317- }
5318- } else if (g_strcmp0 (args [0 ], "statusbar" ) == 0 ) {
5319- if (args [1 ] == NULL ) {
5320- auto_gchar gchar * format = prefs_get_string (PREF_TIME_STATUSBAR );
5321- cons_show ("Status bar time format: '%s'." , format );
5322- return TRUE;
5323- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5324- prefs_set_string (PREF_TIME_STATUSBAR , args [2 ]);
5325- cons_show ("Status bar time format set to '%s'." , args [2 ]);
5326- ui_redraw ();
5327- return TRUE;
5328- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5329- prefs_set_string (PREF_TIME_STATUSBAR , "off" );
5330- cons_show ("Status bar time display disabled." );
5331- ui_redraw ();
5332- return TRUE;
5333- } else {
5334- cons_bad_cmd_usage (command );
5335- return TRUE;
5336- }
5337- } else if (g_strcmp0 (args [0 ], "console" ) == 0 ) {
5338- if (args [1 ] == NULL ) {
5339- auto_gchar gchar * format = prefs_get_string (PREF_TIME_CONSOLE );
5340- cons_show ("Console time format: '%s'." , format );
5341- return TRUE;
5342- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5343- prefs_set_string (PREF_TIME_CONSOLE , args [2 ]);
5344- cons_show ("Console time format set to '%s'." , args [2 ]);
5345- wins_resize_all ();
5346- return TRUE;
5347- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5348- prefs_set_string (PREF_TIME_CONSOLE , "off" );
5349- cons_show ("Console time display disabled." );
5350- wins_resize_all ();
5351- return TRUE;
5352- } else {
5353- cons_bad_cmd_usage (command );
5354- return TRUE;
5355- }
5356- } else if (g_strcmp0 (args [0 ], "chat" ) == 0 ) {
5357- if (args [1 ] == NULL ) {
5358- auto_gchar gchar * format = prefs_get_string (PREF_TIME_CHAT );
5359- cons_show ("Chat time format: '%s'." , format );
5360- return TRUE;
5361- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5362- prefs_set_string (PREF_TIME_CHAT , args [2 ]);
5363- cons_show ("Chat time format set to '%s'." , args [2 ]);
5364- wins_resize_all ();
5365- return TRUE;
5366- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5367- prefs_set_string (PREF_TIME_CHAT , "off" );
5368- cons_show ("Chat time display disabled." );
5369- wins_resize_all ();
5370- return TRUE;
5371- } else {
5372- cons_bad_cmd_usage (command );
5373- return TRUE;
5374- }
5375- } else if (g_strcmp0 (args [0 ], "muc" ) == 0 ) {
5376- if (args [1 ] == NULL ) {
5377- auto_gchar gchar * format = prefs_get_string (PREF_TIME_MUC );
5378- cons_show ("MUC time format: '%s'." , format );
5379- return TRUE;
5380- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5381- prefs_set_string (PREF_TIME_MUC , args [2 ]);
5382- cons_show ("MUC time format set to '%s'." , args [2 ]);
5383- wins_resize_all ();
5384- return TRUE;
5385- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5386- prefs_set_string (PREF_TIME_MUC , "off" );
5387- cons_show ("MUC time display disabled." );
5388- wins_resize_all ();
5389- return TRUE;
5390- } else {
5391- cons_bad_cmd_usage (command );
5392- return TRUE;
5393- }
5394- } else if (g_strcmp0 (args [0 ], "config" ) == 0 ) {
5395- if (args [1 ] == NULL ) {
5396- auto_gchar gchar * format = prefs_get_string (PREF_TIME_CONFIG );
5397- cons_show ("config time format: '%s'." , format );
5398- return TRUE;
5399- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5400- prefs_set_string (PREF_TIME_CONFIG , args [2 ]);
5401- cons_show ("config time format set to '%s'." , args [2 ]);
5402- wins_resize_all ();
5403- return TRUE;
5404- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5405- prefs_set_string (PREF_TIME_CONFIG , "off" );
5406- cons_show ("config time display disabled." );
5407- wins_resize_all ();
5408- return TRUE;
5409- } else {
5410- cons_bad_cmd_usage (command );
5411- return TRUE;
5412- }
5413- } else if (g_strcmp0 (args [0 ], "private" ) == 0 ) {
5414- if (args [1 ] == NULL ) {
5415- auto_gchar gchar * format = prefs_get_string (PREF_TIME_PRIVATE );
5416- cons_show ("Private chat time format: '%s'." , format );
5417- return TRUE;
5418- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5419- prefs_set_string (PREF_TIME_PRIVATE , args [2 ]);
5420- cons_show ("Private chat time format set to '%s'." , args [2 ]);
5421- wins_resize_all ();
5422- return TRUE;
5423- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5424- prefs_set_string (PREF_TIME_PRIVATE , "off" );
5425- cons_show ("Private chat time display disabled." );
5426- wins_resize_all ();
5427- return TRUE;
5428- } else {
5429- cons_bad_cmd_usage (command );
5430- return TRUE;
5431- }
5432- } else if (g_strcmp0 (args [0 ], "xml" ) == 0 ) {
5433- if (args [1 ] == NULL ) {
5434- auto_gchar gchar * format = prefs_get_string (PREF_TIME_XMLCONSOLE );
5435- cons_show ("XML Console time format: '%s'." , format );
5436- return TRUE;
5437- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5438- prefs_set_string (PREF_TIME_XMLCONSOLE , args [2 ]);
5439- cons_show ("XML Console time format set to '%s'." , args [2 ]);
5440- wins_resize_all ();
5441- return TRUE;
5442- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5443- prefs_set_string (PREF_TIME_XMLCONSOLE , "off" );
5444- cons_show ("XML Console time display disabled." );
5445- wins_resize_all ();
5446- return TRUE;
5447- } else {
5448- cons_bad_cmd_usage (command );
5449- return TRUE;
5450- }
5451- } else if (g_strcmp0 (args [0 ], "all" ) == 0 ) {
5452- if (args [1 ] == NULL ) {
5453- cons_time_setting ();
5454- return TRUE;
5455- } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5456- prefs_set_string (PREF_TIME_CONSOLE , args [2 ]);
5457- cons_show ("Console time format set to '%s'." , args [2 ]);
5458- prefs_set_string (PREF_TIME_CHAT , args [2 ]);
5459- cons_show ("Chat time format set to '%s'." , args [2 ]);
5460- prefs_set_string (PREF_TIME_MUC , args [2 ]);
5461- cons_show ("MUC time format set to '%s'." , args [2 ]);
5462- prefs_set_string (PREF_TIME_CONFIG , args [2 ]);
5463- cons_show ("config time format set to '%s'." , args [2 ]);
5464- prefs_set_string (PREF_TIME_PRIVATE , args [2 ]);
5465- cons_show ("Private chat time format set to '%s'." , args [2 ]);
5466- prefs_set_string (PREF_TIME_XMLCONSOLE , args [2 ]);
5467- cons_show ("XML Console time format set to '%s'." , args [2 ]);
5468- wins_resize_all ();
5469- return TRUE;
5470- } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5471- prefs_set_string (PREF_TIME_CONSOLE , "off" );
5472- cons_show ("Console time display disabled." );
5473- prefs_set_string (PREF_TIME_CHAT , "off" );
5474- cons_show ("Chat time display disabled." );
5475- prefs_set_string (PREF_TIME_MUC , "off" );
5476- cons_show ("MUC time display disabled." );
5477- prefs_set_string (PREF_TIME_CONFIG , "off" );
5478- cons_show ("config time display disabled." );
5479- prefs_set_string (PREF_TIME_PRIVATE , "off" );
5480- cons_show ("config time display disabled." );
5481- prefs_set_string (PREF_TIME_XMLCONSOLE , "off" );
5482- cons_show ("XML Console time display disabled." );
5483- ui_redraw ();
5484- return TRUE;
5485- } else {
5486- cons_bad_cmd_usage (command );
5487- return TRUE;
5488- }
5489- } else if (g_strcmp0 (args [0 ], "vcard" ) == 0 ) {
5300+ const struct time_preferences
5301+ {
5302+ preference_t pref ;
5303+ const char * name , * description ;
5304+ } time_prefs [] = {
5305+ { .pref = PREF_TIME_LASTACTIVITY , .name = "lastactivity" , .description = "Last activity" },
5306+ { .pref = PREF_TIME_CONSOLE , .name = "console" , .description = "Console" },
5307+ { .pref = PREF_TIME_STATUSBAR , .name = "statusbar" , .description = "Status bar" },
5308+ { .pref = PREF_TIME_CHAT , .name = "chat" , .description = "Chat" },
5309+ { .pref = PREF_TIME_MUC , .name = "muc" , .description = "MUC" },
5310+ { .pref = PREF_TIME_CONFIG , .name = "config" , .description = "Config" },
5311+ { .pref = PREF_TIME_PRIVATE , .name = "private" , .description = "Private chat" },
5312+ { .pref = PREF_TIME_XMLCONSOLE , .name = "xml" , .description = "XML Console" },
5313+ { .pref = PREF_TIME_VCARD , .name = "vcard" , .description = "vCard" },
5314+ };
5315+ gboolean redraw = FALSE;
5316+ gboolean set_all = g_strcmp0 (args [0 ], "all" ) == 0 ;
5317+ for (size_t n = 0 ; n < ARRAY_SIZE (time_prefs ); ++ n ) {
5318+ if (!set_all && g_strcmp0 (args [0 ], time_prefs [n ].name ) != 0 )
5319+ continue ;
5320+ const struct time_preferences * tp = & time_prefs [n ];
54905321 if (args [1 ] == NULL ) {
5491- auto_gchar gchar * format = prefs_get_string (PREF_TIME_VCARD );
5492- cons_show ("vCard time format: %s" , format );
5493- return TRUE;
5322+ if (set_all ) {
5323+ cons_time_setting ();
5324+ return TRUE;
5325+ }
5326+ auto_gchar gchar * format = prefs_get_string (tp -> pref );
5327+ cons_show ("%s time format: '%s'." , tp -> description , format );
54945328 } else if (g_strcmp0 (args [1 ], "set" ) == 0 && args [2 ] != NULL ) {
5495- prefs_set_string (PREF_TIME_VCARD , args [2 ]);
5496- cons_show ("vCard time format set to '%s'." , args [2 ]);
5497- ui_redraw ();
5498- return TRUE;
5329+ const struct format_strings
5330+ {
5331+ const char * name , * format ;
5332+ } format_strings [] = {
5333+ { .name = "iso8601" , .format = "%Y-%m-%dT%H:%M:%S" },
5334+ };
5335+ const gchar * set_arg = args [2 ];
5336+ for (size_t m = 0 ; m < ARRAY_SIZE (format_strings ); ++ m ) {
5337+ if (g_strcmp0 (args [2 ], format_strings [m ].name ) == 0 ) {
5338+ set_arg = format_strings [m ].format ;
5339+ break ;
5340+ }
5341+ }
5342+ prefs_set_string (tp -> pref , set_arg );
5343+ cons_show ("%s time format set to '%s'." , tp -> description , args [2 ]);
5344+ redraw = TRUE;
54995345 } else if (g_strcmp0 (args [1 ], "off" ) == 0 ) {
5500- cons_show ("vCard time cannot be disabled." );
5501- ui_redraw ();
5502- return TRUE;
5346+ if (tp -> pref == PREF_TIME_LASTACTIVITY ) {
5347+ cons_show ("%s time display cannot be disabled." , tp -> description );
5348+ } else {
5349+ prefs_set_string (tp -> pref , "off" );
5350+ cons_show ("%s time display disabled." , tp -> description );
5351+ redraw = TRUE;
5352+ }
55035353 } else {
55045354 cons_bad_cmd_usage (command );
55055355 return TRUE;
55065356 }
5507- } else {
5508- cons_bad_cmd_usage (command );
5509- return TRUE;
55105357 }
5358+ if (redraw )
5359+ ui_redraw ();
5360+ return TRUE;
55115361}
55125362
55135363gboolean
0 commit comments