spek

Acoustic spectrum analyser https://github.com/alexkay/spek spek.cc
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

spek.cc (2200B)


      1 #include <wx/cmdline.h>
      2 #include <wx/log.h>
      3 #include <wx/socket.h>
      4 
      5 #include "spek-artwork.h"
      6 #include "spek-platform.h"
      7 #include "spek-preferences.h"
      8 
      9 #include "spek-window.h"
     10 
     11 class Spek: public wxApp
     12 {
     13 public:
     14     Spek() : wxApp(), window(NULL), quit(false) {}
     15 
     16 protected:
     17     virtual bool OnInit();
     18     virtual int OnRun();
     19 #ifdef OS_OSX
     20     virtual void MacOpenFiles(const wxArrayString& files);
     21 #endif
     22 
     23 private:
     24     SpekWindow *window;
     25     wxString path;
     26     bool quit;
     27 };
     28 
     29 IMPLEMENT_APP(Spek)
     30 
     31 bool Spek::OnInit()
     32 {
     33     wxInitAllImageHandlers();
     34     wxSocketBase::Initialize();
     35 
     36     spek_artwork_init();
     37     spek_platform_init();
     38     SpekPreferences::get().init();
     39 
     40     static const wxCmdLineEntryDesc desc[] = {{
     41             wxCMD_LINE_SWITCH,
     42             "h",
     43             "help",
     44             "Show this help message",
     45             wxCMD_LINE_VAL_NONE,
     46             wxCMD_LINE_OPTION_HELP,
     47         }, {
     48             wxCMD_LINE_SWITCH,
     49             "V",
     50             "version",
     51             "Display the version and exit",
     52             wxCMD_LINE_VAL_NONE,
     53             wxCMD_LINE_PARAM_OPTIONAL,
     54         }, {
     55             wxCMD_LINE_PARAM,
     56             NULL,
     57             NULL,
     58             "FILE",
     59             wxCMD_LINE_VAL_STRING,
     60             wxCMD_LINE_PARAM_OPTIONAL,
     61         },
     62         wxCMD_LINE_DESC_END,
     63     };
     64 
     65     wxCmdLineParser parser(desc, argc, argv);
     66     int ret = parser.Parse(true);
     67     if (ret == 1) {
     68         return false;
     69     }
     70     if (ret == -1) {
     71         this->quit = true;
     72         return true;
     73     }
     74     if (parser.Found("version")) {
     75         // TRANSLATORS: the %s is the package version.
     76         wxPrintf(_("Spek version %s"), PACKAGE_VERSION);
     77         wxPrintf("\n");
     78         this->quit = true;
     79         return true;
     80     }
     81     if (parser.GetParamCount()) {
     82         this->path = parser.GetParam();
     83     }
     84 
     85     this->window = new SpekWindow(this->path);
     86     this->window->Show(true);
     87     SetTopWindow(this->window);
     88     return true;
     89 }
     90 
     91 int Spek::OnRun()
     92 {
     93     if (quit) {
     94         return 0;
     95     }
     96 
     97     return wxApp::OnRun();
     98 }
     99 
    100 #ifdef OS_OSX
    101 void Spek::MacOpenFiles(const wxArrayString& files)
    102 {
    103     if (files.GetCount() == 1) {
    104         this->window->open(files[0]);
    105     }
    106 }
    107 #endif