Exemple #1
0
int
main (int argc, char **argv)
{
    /* init i18n */
    setlocale (LC_ALL, "");
    bindtextdomain(GETTEXT_PACKAGE, SEAFILE_LOCALE_DIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);

    if (count_process("seafile-applet") > 1) {
        fprintf(stderr, _("Seafile is already running\n"));
        exit(1);
    }

    gtk_init (&argc, &argv);
    gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
                                       PKGDATADIR);
    gtk_window_set_default_icon_name ("seafile");

    signal (SIGINT, sigint_handler);

    applet = g_new0 (SeafileApplet, 1);
    seafile_applet_init (applet);
    seafile_applet_start (argc, argv);

    applet_message ("seafile started\n");

    trayicon_set_tip ("Seafile");

    gtk_main ();

    return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
#ifdef Q_WS_MAC
    Application app(argc, argv);
#else
    QApplication app(argc, argv);
#endif

    if (count_process("seafile-applet") > 1) {
        QMessageBox::warning(NULL, "Seafile",
                             QObject::tr("Seafile is already running"),
                             QMessageBox::Ok);
        return -1;
    }


    app.setQuitOnLastWindowClosed(false);

    // see QSettings documentation
    QCoreApplication::setOrganizationName("Seafile");
    QCoreApplication::setOrganizationDomain("seafile.com");
    QCoreApplication::setApplicationName("Seafile Client");

    // initialize i18n
    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(),
                      QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);

    QTranslator myappTranslator;
    myappTranslator.load(QString(":/i18n/seafile_%1.qm").arg(QLocale::system().name()));
    app.installTranslator(&myappTranslator);


#if !GLIB_CHECK_VERSION(2, 35, 0)
    g_type_init();
#endif
#if !GLIB_CHECK_VERSION(2, 31, 0)
    g_thread_init(NULL);
#endif

    awesome = new QtAwesome(qApp);
    awesome->initFontAwesome();

    seafApplet = new SeafileApplet;
    seafApplet->start();

    return app.exec();
}
Exemple #3
0
int main(int argc, char *argv[])
{
    int ret = 0;
    char c;
#ifdef Q_WS_MAC
    if ( QSysInfo::MacintoshVersion > QSysInfo::MV_10_8 ) {
        // fix Mac OS X 10.9 (mavericks) font issue
        // https://bugreports.qt-project.org/browse/QTBUG-32789
        QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
    }
#endif

#if !GLIB_CHECK_VERSION(2, 35, 0)
    g_type_init();
#endif
#if !GLIB_CHECK_VERSION(2, 31, 0)
    g_thread_init(NULL);
#endif

#ifdef Q_WS_MAC
    Application app(argc, argv);
#else
    QApplication app(argc, argv);
#endif

    QDir::setCurrent(QApplication::applicationDirPath());
    app.setStyle(new SeafileProxyStyle());

    // initialize i18n
    QTranslator qtTranslator;
#if defined(Q_WS_WIN)
    qtTranslator.load("qt_" + QLocale::system().name());
#else
    qtTranslator.load("qt_" + QLocale::system().name(),
                      QLibraryInfo::location(QLibraryInfo::TranslationsPath));
#endif
    app.installTranslator(&qtTranslator);

    QTranslator myappTranslator;
#if QT_VERSION >= 0x040800 && not defined(Q_WS_MAC)
    QLocale loc = QLocale::system();
    QString lang = QLocale::languageToString(loc.language());

    if (lang != "en") {
        bool success;
        success = myappTranslator.load(QLocale::system(), // locale
                                       "",                // file name
                                       "seafile_",        // prefix
                                       ":/i18n/",         // folder
                                       ".qm");            // suffix

        if (!success) {
            myappTranslator.load(QString(":/i18n/seafile_%1.qm").arg(QLocale::system().name()));
        }
    }
#else
    myappTranslator.load(QString(":/i18n/seafile_%1.qm").arg(QLocale::system().name()));
#endif

    app.installTranslator(&myappTranslator);

    static const char *short_options = "KXc:d:f:";
    static const struct option long_options[] = {
        { "config-dir", required_argument, NULL, 'c' },
        { "data-dir", required_argument, NULL, 'd' },
        { "stop", no_argument, NULL, 'K' },
        { "remove-user-data", no_argument, NULL, 'X' },
        { "open-local-file", no_argument, NULL, 'f' },
        { "stdout", no_argument, NULL, 'l' },
        { NULL, 0, NULL, 0, },
    };

    while ((c = getopt_long (argc, argv, short_options,
                             long_options, NULL)) != EOF) {
        switch (c) {
        case 'c':
            g_setenv ("CCNET_CONF_DIR", optarg, 1);
            break;
        case 'd':
            g_setenv ("SEAFILE_DATA_DIR", optarg, 1);
            break;
        case 'l':
            g_setenv ("LOG_STDOUT", "", 1);
            break;
        case 'K':
            do_stop();
            exit(0);
        case 'X':
            do_remove_user_data();
            exit(0);
        case 'f':
            OpenLocalHelper::instance()->handleOpenLocalFromCommandLine(optarg);
            break;
        default:
            exit(1);
        }
    }

    if (count_process(APPNAME) > 1) {
        QMessageBox::warning(NULL, getBrand(),
                             QObject::tr("%1 is already running").arg(getBrand()),
                             QMessageBox::Ok);
        return -1;
    }

    app.setQuitOnLastWindowClosed(false);

    // see QSettings documentation
    QCoreApplication::setOrganizationName(getBrand());
    QCoreApplication::setOrganizationDomain("seafile.com");
    QCoreApplication::setApplicationName(QString("%1 Client").arg(getBrand()));

    awesome = new QtAwesome(qApp);
    awesome->initFontAwesome();

    seafApplet = new SeafileApplet;
    seafApplet->start();

    ret = app.exec();
    seafApplet->exit(ret);
    return ret;
}
Exemple #4
0
int main(int argc, char *argv[])
{
    int ret = 0;

    // call glib's init functions
    initGlib();

    // initialize breakpad if enabled
    initBreakpad();

    // Apply hidpi support
    setupHIDPIFix();

    // TODO imple if we have to restart the application
    // the manual at http://qt-project.org/wiki/ApplicationRestart
#if defined(Q_OS_MAC)
    Application app(argc, argv);
#else
    QApplication app(argc, argv);
#endif
#if defined(Q_OS_WIN32)
    // change the current directory
    QDir::setCurrent(QApplication::applicationDirPath());
#endif

    // don't quit even if the last windows is closed
    app.setQuitOnLastWindowClosed(false);

    // apply some ui fixes for mac
    setupFontFix();

    // set the domains of settings
    setupSettingDomain();

    // initialize i18n settings
    I18NHelper::getInstance()->init();

    // initialize style settings
    app.setStyle(new SeafileProxyStyle());

    // handle with the command arguments
    handleCommandLineOption(argc, argv);

    // count if we have any instance running now. if more than one, exit
    if (count_process(APPNAME) > 1) {
        // have we activated it ? exit
        if (SharedApplication::activate())
            return 0;
        if (QMessageBox::No == QMessageBox::warning(NULL, getBrand(),
                QObject::tr("Found another running process of %1, kill it and start a new one?").arg(getBrand()),
                QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)) {
            return -1;
        }

        // sleep 9 * 100ms to await the os completing the operation
        do_stop();
        int n = 10;
        while(--n >0 && count_process(APPNAME) > 1)
            msleep(100);

        // force shutdown it
        if (count_process(APPNAME) > 1) {
            shutdown_process(APPNAME);
            msleep(100);
        }

        // count if we still have any instance running now. if more than one, exit
        if (count_process(APPNAME) > 1) {
            QMessageBox::critical(NULL, getBrand(),
                QObject::tr("Unable to start %1 due to the failure of shutting down the previous process").arg(getBrand()),
                QMessageBox::Ok);
            return -1;
        }
    }

    // init qtawesome component
    awesome = new QtAwesome(qApp);
    awesome->initFontAwesome();

    // start applet
    SeafileApplet mApplet;
    seafApplet = &mApplet;
    seafApplet->start();

    // start qt eventloop
    ret = app.exec();

    return ret;
}
Exemple #5
0
/* process a line from the log and store it accordingly */
static int
process_log (GLog * logger, char *line, int test)
{
  GLogItem *glog;
  char date[DATE_LEN];
  char *qmark = NULL, *req_key = NULL;
  int is404 = 0;

  if (valid_line (line)) {
    count_invalid (logger);
    return 0;
  }

  count_process (logger);
  glog = init_log_item (logger);
  /* parse a line of log, and fill structure with appropriate values */
  if (parse_format (glog, conf.log_format, conf.date_format, line)) {
    count_invalid (logger);
    goto cleanup;
  }

  /* must have the following fields */
  if (glog->host == NULL || glog->date == NULL || glog->req == NULL) {
    count_invalid (logger);
    goto cleanup;
  }
  /* agent will be null in cases where %u is not specified */
  if (glog->agent == NULL)
    glog->agent = alloc_string ("-");

  /* testing log only */
  if (test)
    goto cleanup;

  if (process_date (glog, date)) {
    count_invalid (logger);
    goto cleanup;
  }
  /* ignore host or crawlers */
  if (exclude_ip (logger, glog) == 0)
    goto cleanup;
  if (exclude_crawler (glog) == 0)
    goto cleanup;
  if (ignore_referer (glog->site))
    goto cleanup;

  /* is this a 404? */
  if (glog->status && !memcmp (glog->status, "404", 3))
    is404 = 1;
  /* treat 444 as 404? */
  else if (glog->status && !memcmp (glog->status, "444", 3) &&
           conf.code444_as_404)
    is404 = 1;
  /* check if we need to remove the request's query string */
  else if (conf.ignore_qstr) {
    if ((qmark = strchr (glog->req, '?')) != NULL) {
      if ((qmark - glog->req) > 0)
        *qmark = '\0';
    }
  }

  req_key = xstrdup (glog->req);
  /* include HTTP method/protocol to request */
  if (conf.append_method && glog->method) {
    glog->method = strtoupper (glog->method);
    append_method_to_request (&req_key, glog->method);
  }
  if (conf.append_protocol && glog->protocol) {
    glog->protocol = strtoupper (glog->protocol);
    append_protocol_to_request (&req_key, glog->protocol);
  }
  if ((conf.append_method) || (conf.append_protocol))
    req_key = deblank (req_key);

  unique_data (glog, date);
  /* process agents that are part of a host */
  if (conf.list_agents)
    process_host_agents (glog->host, glog->agent);
  /* process status codes */
  if (glog->status)
    process_generic_data (ht_status_code, glog->status);
  /* process 404s */
  if (is404)
    process_request (ht_not_found_requests, req_key, glog);
  /* process static files */
  else if (verify_static_content (glog->req))
    process_request (ht_requests_static, req_key, glog);
  /* process regular files */
  else
    process_request (ht_requests, req_key, glog);

  /* process referrers */
  process_referrers (glog->ref, glog->site);
  /* process hosts */
  process_generic_data (ht_hosts, glog->host);
  /* process bandwidth  */
  process_request_meta (ht_date_bw, date, glog->resp_size);
  process_request_meta (ht_file_bw, req_key, glog->resp_size);
  process_request_meta (ht_host_bw, glog->host, glog->resp_size);

  /* process time taken to serve the request, in microseconds */
  process_request_meta (ht_file_serve_usecs, req_key, glog->serve_time);
  process_request_meta (ht_host_serve_usecs, glog->host, glog->serve_time);

  logger->resp_size += glog->resp_size;
#ifdef TCB_BTREE
  process_request_meta (ht_general_stats, "bandwidth", glog->resp_size);
#endif

cleanup:
  free_logger (glog);
  if (req_key != NULL)
    free (req_key);

  return 0;
}
int count_process(const char *name, uint64_t *pid)
{
    return count_process(name);
}
Exemple #7
0
int
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (set_applet_wd() < 0) 
        return -1;

#ifdef SEAF_LANG_CHINESE
    char *seafile_locale_dir = g_build_filename (seafile_bin_dir,
                                                 "i18n", NULL);
    /* init i18n */
    setlocale (LC_ALL, "zh_CN");
    bindtextdomain(GETTEXT_PACKAGE, seafile_locale_dir);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "GBK");
    textdomain(GETTEXT_PACKAGE);
#endif
    
    if (count_process("seafile-applet") > 1) {
        MessageBox(NULL, _("Seafile is already running"), "Seafile", MB_OK);
        exit(1);
    }
    
    int argc;
    char **argv;
    char  cmdbuf[1024];
    GError *err = NULL;

    WSADATA     wsadata;
    WSAStartup(0x0101, &wsadata);

    UNREFERENCED_PARAMETER(hPrevInstance);

    snprintf(cmdbuf, sizeof(cmdbuf), "seafile-applet.exe %s", lpCmdLine);

    char *xxx = _("Seafile Initialization");
    char tmp[128];

    snprintf(tmp, sizeof(tmp), "%s", xxx);

    if (!g_shell_parse_argv (cmdbuf, &argc, &argv, &err)) {
        if (err)
            applet_warning ("parse arguments failed %s\n", err->message);
        applet_exit(1);
    }

    g_type_init();

    applet = g_new0 (SeafileApplet, 1);

    seafile_applet_init (hInstance);
    seafile_applet_start (argc, argv);

    MSG msg;
    HACCEL hAccelTable;

    memset(&msg, 0, sizeof(msg));
    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_STARTINTRAY));

    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}