~ubuntu-branches/debian/stretch/gource/stretch

« back to all changes in this revision

Viewing changes to src/gource_settings.cpp

  • Committer: Package Import Robot
  • Author(s): Andrew Caudwell
  • Date: 2014-04-15 16:30:17 UTC
  • mfrom: (1.2.15)
  • Revision ID: package-import@ubuntu.com-20140415163017-ucdr2josj1spzrga
Tags: 0.41-1
* New upstream release
* Made VCS URIs canonical
* Changed watch file to look at Github for releases

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "core/sdlapp.h"
20
20
 
21
21
#include <boost/filesystem.hpp>
 
22
#include <boost/format.hpp>
22
23
#include <boost/algorithm/string.hpp>
23
24
 
24
25
#include "core/utf8/utf8.h"
 
26
#include <time.h>
 
27
 
 
28
#include "formats/hg.h"
 
29
#include "formats/git.h"
 
30
#include "formats/bzr.h"
 
31
#include "formats/cvs-exp.h"
 
32
#include "formats/cvs2cl.h"
 
33
#include "formats/svn.h"
25
34
 
26
35
GourceSettings gGourceSettings;
27
36
 
30
39
 
31
40
#ifdef _WIN32
32
41
    //resize window to fit help message
33
 
    SDLApp::resizeConsole(820);
 
42
    SDLApp::resizeConsole(730);
34
43
    SDLApp::showConsole(true);
35
44
#endif
36
45
 
44
53
    printf("      --multi-sampling             Enable multi-sampling\n");
45
54
    printf("      --no-vsync                   Disable vsync\n\n");
46
55
 
47
 
    printf("  -p, --start-position POSITION    Begin at some position (0.0-1.0 or 'random')\n");
 
56
    printf("  --start-date 'YYYY-MM-DD hh:mm:ss +tz'  Start at a date and optional time\n");
 
57
    printf("  --stop-date  'YYYY-MM-DD hh:mm:ss +tz'  Stop at a date and optional time\n\n");
 
58
    printf("  -p, --start-position POSITION    Start at some position (0.0-1.0 or 'random')\n");
48
59
    printf("      --stop-position  POSITION    Stop at some position\n");
49
60
    printf("  -t, --stop-at-time SECONDS       Stop after a specified number of seconds\n");
50
61
    printf("      --stop-at-end                Stop at end of the log\n");
65
76
    printf("  --default-user-image IMAGE       Default user image file\n");
66
77
    printf("  --colour-images                  Colourize user images\n\n");
67
78
 
68
 
    printf("  -i, --file-idle-time SECONDS     Time files remain idle (default: 60)\n\n");
69
 
 
70
 
    printf("  --max-files NUMBER       Max number of files or 0 for no limit\n");
71
 
    printf("  --max-file-lag SECONDS   Max time files of a commit can take to appear\n\n");
72
 
 
73
 
    printf("  --log-command VCS        Show the VCS log command (git,svn,hg,bzr,cvs2cl)\n");
74
 
    printf("  --log-format  VCS        Specify the log format (git,svn,hg,bzr,cvs2cl,custom)\n\n");
 
79
    printf("  -i, --file-idle-time SECONDS     Time files remain idle (default: 0)\n\n");
 
80
 
 
81
    printf("  --max-files NUMBER      Max number of files or 0 for no limit\n");
 
82
    printf("  --max-file-lag SECONDS  Max time files of a commit can take to appear\n\n");
 
83
 
 
84
    printf("  --log-command VCS       Show the VCS log command (git,svn,hg,bzr,cvs2cl)\n");
 
85
    printf("  --log-format  VCS       Specify the log format (git,svn,hg,bzr,cvs2cl,custom)\n\n");
75
86
 
76
87
    printf("  --load-config CONF_FILE  Load a config file\n");
77
88
    printf("  --save-config CONF_FILE  Save a config file with the current options\n\n");
128
139
    printf("  --highlight-users        Highlight the names of all users\n\n");
129
140
    printf("  --highlight-colour       Font colour for highlighted users in hex.\n");
130
141
    printf("  --selection-colour       Font colour for selected users and files.\n");
131
 
    printf("  --dir-colour             Font colour for directories.\n\n");
 
142
    printf("  --dir-colour             Font colour for directories.\n");
 
143
    printf("  --dir-name-depth DEPTH   Draw names of directories down to a specific depth.\n\n");
132
144
 
133
145
    printf("  --caption-file FILE         Caption file\n");
134
146
    printf("  --caption-size SIZE         Caption font size\n");
163
175
    repo_count = 0;
164
176
    file_graphic = 0;
165
177
    log_level = LOG_LEVEL_OFF;
 
178
    shutdown = false;
166
179
 
167
180
    setGourceDefaults();
168
181
 
274
287
    arg_types["log-format"]         = "string";
275
288
    arg_types["git-branch"]         = "string";
276
289
    arg_types["start-position"]     = "string";
 
290
    arg_types["start-date"]         = "string";
 
291
    arg_types["stop-date"]          = "string";
277
292
    arg_types["stop-position"]      = "string";
278
293
    arg_types["crop"]               = "string";
279
294
    arg_types["hide"]               = "string";
292
307
    arg_types["caption-colour"]     = "string";
293
308
    arg_types["caption-offset"]     = "int";
294
309
 
295
 
 
 
310
    arg_types["dir-name-depth"]     = "int";
296
311
}
297
312
 
298
313
void GourceSettings::setGourceDefaults() {
314
329
    hide_mouse     = false;
315
330
    hide_root      = false;
316
331
 
 
332
    start_timestamp = 0;
 
333
    start_date = "";
 
334
 
 
335
    stop_timestamp = 0;
 
336
    stop_date = "";
 
337
 
317
338
    start_position = 0.0f;
318
339
    stop_position  = 0.0f;
319
340
    stop_at_time   = -1.0f;
327
348
 
328
349
    auto_skip_seconds = 3.0f;
329
350
    days_per_second   = 0.1f; // TODO: check this is right
330
 
    file_idle_time    = 60.0f;
 
351
    file_idle_time    = 0.0f;
331
352
    time_scale        = 1.0f;
332
353
 
333
354
    loop = false;
364
385
    highlight_colour = vec3(1.0f);
365
386
    selection_colour = vec3(1.0, 1.0, 0.3f);
366
387
 
 
388
    dir_name_depth = 0;
 
389
 
367
390
    elasticity = 0.0f;
368
391
 
369
392
    git_branch = "";
433
456
    }
434
457
 
435
458
    if(name == "git-log-command" || log_command == "git") {
436
 
        SDLAppInfo(gGourceGitLogCommand);
 
459
        SDLAppInfo(GitCommitLog::logCommand());
437
460
    }
438
461
 
439
462
    if(name == "cvs-exp-command" || log_command == "cvs-exp") {
440
 
        SDLAppInfo(gGourceCvsExpLogCommand);
 
463
        SDLAppInfo(CVSEXPCommitLog::logCommand());
441
464
    }
442
465
 
443
466
    if(log_command == "cvs") {
445
468
    }
446
469
 
447
470
    if(name == "cvs2cl-command" || log_command == "cvs2cl") {
448
 
        SDLAppInfo(gGourceCVS2CLLogCommand);
 
471
        SDLAppInfo(CVS2CLCommitLog::logCommand());
449
472
    }
450
473
 
451
474
    if(name == "svn-log-command" || log_command == "svn") {
452
 
        SDLAppInfo(gGourceSVNLogCommand);
 
475
        SDLAppInfo(SVNCommitLog::logCommand());
453
476
    }
454
477
 
455
478
    if(name == "hg-log-command" || log_command == "hg") {
456
 
        std::string command = gGourceMercurialCommand();
457
 
        SDLAppInfo(command);
 
479
        SDLAppInfo(MercurialLog::logCommand());
458
480
    }
459
481
 
460
482
    if(name == "bzr-log-command" || log_command == "bzr") {
461
 
        std::string command = gGourceBzrLogCommand();
462
 
        SDLAppInfo(command);
 
483
        SDLAppInfo(BazaarLog::logCommand());
463
484
    }
464
485
 
465
486
    if(name == "output-custom-log" && value.size() > 0) {
607
628
 
608
629
        if(!entry->hasValue()) conffile.missingValueException(entry);
609
630
 
610
 
        git_branch = entry->getString();
 
631
        Regex branch_regex("^(?!-)[/\\w.,;_=+{}\\[\\]-]+$");
 
632
 
 
633
        std::string branch = entry->getString();
 
634
 
 
635
        if(branch_regex.match(branch)) {
 
636
            git_branch = branch;
 
637
        } else {
 
638
            conffile.invalidValueException(entry);
 
639
        }
611
640
    }
612
641
 
613
642
    if(gource_settings->getBool("colour-images")) {
991
1020
        if(file_idle_time<0.0f || (file_idle_time == 0.0f && file_idle_str[0] != '0') ) {
992
1021
            conffile.invalidValueException(entry);
993
1022
        }
994
 
        if(file_idle_time==0.0f) {
995
 
            file_idle_time = 86400.0f;
996
 
        }
997
1023
    }
998
1024
 
999
1025
    if((entry = gource_settings->getEntry("user-idle-time")) != 0) {
1019
1045
        }
1020
1046
    }
1021
1047
 
 
1048
    if((entry = gource_settings->getEntry("start-date")) != 0) {
 
1049
 
 
1050
        if(!entry->hasValue()) conffile.entryException(entry, "specify start-date (YYYY-MM-DD hh:mm:ss)");
 
1051
 
 
1052
        std::string start_date_string = entry->getString();
 
1053
 
 
1054
        if(parseDateTime(start_date_string, start_timestamp)) {
 
1055
 
 
1056
            char datestr[256];
 
1057
            strftime(datestr, 256, "%Y-%m-%d", localtime ( &start_timestamp ));
 
1058
            start_date = datestr;
 
1059
 
 
1060
        } else {
 
1061
            conffile.invalidValueException(entry);
 
1062
        }
 
1063
    }
 
1064
 
 
1065
    if((entry = gource_settings->getEntry("stop-date")) != 0) {
 
1066
 
 
1067
        if(!entry->hasValue()) conffile.entryException(entry, "specify stop-date (YYYY-MM-DD hh:mm:ss)");
 
1068
 
 
1069
        std::string end_date_string = entry->getString();
 
1070
 
 
1071
        if(parseDateTime(end_date_string, stop_timestamp)) {
 
1072
 
 
1073
            struct tm * timeinfo;
 
1074
            timeinfo = localtime ( &stop_timestamp );
 
1075
 
 
1076
            time_t stop_timestamp_rounded = stop_timestamp;
 
1077
 
 
1078
            if(timeinfo->tm_hour > 0 || timeinfo->tm_min > 0 || timeinfo->tm_sec > 0) {
 
1079
                stop_timestamp_rounded += 60*60*24;
 
1080
            }
 
1081
 
 
1082
            char datestr[256];
 
1083
            strftime(datestr, 256, "%Y-%m-%d", localtime ( &stop_timestamp_rounded ));
 
1084
            stop_date = datestr;
 
1085
 
 
1086
        } else {
 
1087
            conffile.invalidValueException(entry);
 
1088
        }
 
1089
    }
 
1090
 
1022
1091
    if((entry = gource_settings->getEntry("start-position")) != 0) {
1023
1092
 
1024
1093
        if(!entry->hasValue()) conffile.entryException(entry, "specify start-position (float,random)");
1250
1319
        }
1251
1320
    }
1252
1321
 
 
1322
    if((entry = gource_settings->getEntry("dir-name-depth")) != 0) {
 
1323
 
 
1324
        if(!entry->hasValue()) conffile.entryException(entry, "specify dir-name-depth (depth)");
 
1325
 
 
1326
        dir_name_depth = entry->getInt();
 
1327
 
 
1328
        if(dir_name_depth <= 0) {
 
1329
            conffile.invalidValueException(entry);
 
1330
        }
 
1331
    }
 
1332
 
1253
1333
    //validate path
1254
1334
    if(gource_settings->hasValue("path")) {
1255
1335
        path = gource_settings->getString("path");
1275
1355
#endif
1276
1356
 
1277
1357
        std::cin.clear();
1278
 
    }
1279
 
 
1280
 
    //remove trailing slash and check if path is a directory
1281
 
    if(path.size() &&
1282
 
    (path[path.size()-1] == '\\' || path[path.size()-1] == '/')) {
1283
 
        path = path.substr(0,path.size()-1);
1284
 
    }
1285
 
 
1286
 
#ifdef _WIN32
1287
 
    //on windows, pre-open console window if we think this is a directory the
1288
 
    //user is trying to open, as system() commands will create a console window
1289
 
    //if there isn't one anyway.
1290
 
 
1291
 
    bool isdir = false;
1292
 
 
1293
 
    if(path.size()>0) {
1294
 
        struct stat fileinfo;
1295
 
        int rc = stat(path.c_str(), &fileinfo);
1296
 
 
1297
 
        if(rc==0 && fileinfo.st_mode & S_IFDIR) isdir = true;
1298
 
    }
1299
 
#endif
 
1358
 
 
1359
    } else if(!path.empty() && path != ".") {
 
1360
 
 
1361
        //remove trailing slash
 
1362
        if(path[path.size()-1] == '\\' || path[path.size()-1] == '/') {
 
1363
            path.resize(path.size()-1);
 
1364
        }
 
1365
 
 
1366
        // check path exists
 
1367
        if(!boost::filesystem::exists(path)) {
 
1368
            throw ConfFileException(str(boost::format("'%s' does not appear to be a valid file or directory") % path), "", 0);
 
1369
        }
 
1370
    }
1300
1371
}