コード例 #1
0
ファイル: gtox.cpp プロジェクト: KoKuToru/gTox
int gTox::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line) {
    utils::debug::scope_log log(DBG_LVL_1("gtox"), {});
    int argc = 0;
    auto argv = command_line ? command_line->get_arguments(argc) : nullptr;
    std::vector<std::string> arguments;
    for(int i = 1; i < argc; ++i) {
        arguments.push_back(argv[i]);
    }

    Gio::Application::type_vec_files files;
    std::vector<std::string> invites;
    for (auto value : arguments) {
        if (Glib::str_has_prefix(value, "tox://")) {
            invites.push_back(value.substr(strlen("tox://")));
            std::clog << "Invite: " << invites.back() << std::endl;
        } else if (Glib::str_has_prefix(value, "tox:")) {
            invites.push_back(value.substr(strlen("tox:")));
            std::clog << "Invite: " << invites.back() << std::endl;
        } else if (value.find('-') != 0) {
            files.push_back(Gio::File::create_for_path(value));
            std::clog << "Open: " << value << std::endl;
        }
    }

    if (!files.empty()) {
        open(files);
    }

    if (!invites.empty()) {
        //invite.. send signal too all ?
        /*for(auto w : get_windows()) {
            auto dialog = dynamic_cast<DialogContact*>(w);
            if (dialog) {
                //TODO: invites
            }
        }*/
    }

    if (invites.empty() && files.empty()) {
        activate();
    }

    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: application.cpp プロジェクト: DevMaggio/ganash2
int Ganash::Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>&command_line)
{
  g_print("on_command_line\n");

  // @see example http://git.gnome.org/browse/glibmm/tree/examples/options/main.cc?h=glibmm-2-24
  // @see console|graphic http://stackoverflow.com/questions/13852421/gtkmm-3-parse-command-line-with-gtkapplication

  bool          entry_version = FALSE;
  bool          entry_license = FALSE;
  bool          entry_mode    = FALSE;


  Glib::OptionContext context("[FICHIER|URI...]");

  Glib::OptionEntry option_version;
  option_version.set_short_name('v');
  option_version.set_long_name("version");
  option_version.set_description("Affiche l'information de version et quitte");

  Glib::OptionEntry option_license;
  option_license.set_short_name('l');
  option_license.set_long_name("license");
  option_license.set_description("Affiche l'information de licence et quitte");

  Glib::OptionEntry option_mode;
  option_mode.set_short_name('c');
  option_mode.set_long_name("console");
  option_mode.set_description("Lance l'application en mode console interactif");

  Glib::OptionGroup group_application("options", "Options de l'application :", "Affiche les options de l'application");
  group_application.add_entry(option_version, entry_version);
  group_application.add_entry(option_license, entry_license);
  group_application.add_entry(option_mode,    entry_mode);
  context.add_group(group_application);

  int argc;
  char **argv = command_line->get_arguments(argc);
  loc_argc = argc;
  loc_argv = argv;

  try
  {
    context.parse(argc, argv);
    if(entry_version)
      {
        print_version();
        // Ganash::ApplicationCommand::print_version();
      }
    else if(entry_license)
      {
        print_license();
        // Ganash::ApplicationCommand::print_license();
      }
    if(entry_mode)
      {
        g_print("console activate\n");
      }
    else
      {
        activate();
      }
  }
  catch(const Glib::Error& ex)
  {
    g_print("%s\n", ex.what().c_str() );
  }


  return 0;
}
コード例 #3
0
int
#ifndef LIFEO_WINDOZE
Lifeograph::on_command_line( const Glib::RefPtr< Gio::ApplicationCommandLine >& cmd_line )
{
    int argc;
    char** argv( cmd_line->get_arguments( argc ) );

    for( int i = 1; i < argc; i++ )

#else
Lifeograph::on_command_line( int argc, char** argv )
{
    for( int i = 0; i < argc; i++ )
#endif

    {
        if( ! strcmp( argv[ i ], "--open" ) || ! strcmp( argv[ i ], "-o" ) )
        {
            if( ( i + 1 ) < argc )
            {
                if( access( argv[ ++i ], F_OK ) == 0 ) // check existance
                {
                    if( ! is_dir( argv[ i ] ) )
                    {
                        WinAppWindow::p->m_login->m_path_cur = argv[ i ];
                        m_flag_open_directly = true;
                    }
                }
                if( ! m_flag_open_directly )
                    Error( "File cannot be opened" );
            }
            else
                Error( "No path provided" );
        }
        else
        if( ! strcmp( argv[ i ], "--force-welcome" ) )
        {
            m_flag_force_welcome = true;
        }
        else
        if( ! strcmp( argv[ i ], "--ignore-locks" ) )
        {
            Diary::s_flag_ignore_locks = true;
        }
        else
        if( ! strcmp( argv[ i ], "--read-only" ) || ! strcmp( argv[ i ], "-r" ) )
        {
            m_flag_read_only = true;
        }
        else
        if( access( argv[ i ], F_OK ) == 0 && ! is_dir( argv[ i ] ) )
        {
            WinAppWindow::p->m_login->m_path_cur = argv[ i ];
            m_flag_open_directly = true;
        }
        else
        {
            print_info( std::string( "Unrecognized argument: " ) + argv[ i ] );
        }
    }

#ifndef LIFEO_WINDOZE
    activate();
#endif

    return 0;
}

#ifndef LIFEO_WINDOZE
bool
Lifeograph::load_gui( const std::string& path )
{
    builder = Gtk::Builder::create();
    try
    {
        builder->add_from_file( path );
    }
    catch( const Glib::FileError& ex )
    {
        print_error( "FileError: " + ex.what() );
        return false;
    }
    catch( const Gtk::BuilderError& ex )
    {
        print_error( "BuilderError: " + ex.what() );
        return false;
    }

    return true;
}