コード例 #1
0
ファイル: Application.cs プロジェクト: teotikalki/tasque
        public void Init(string[] args)
        {
            lock (locker) {
                if (initialized)
                {
                    return;
                }
                initialized = true;
            }

            nativeApp.Initialize(
                Defines.LocaleDir,
                "Tasque",
                "Tasque",
                args);

            preferences = new Preferences(nativeApp.ConfDir);

#if !WIN && !OSX
            // Register Tasque RemoteControl
            try {
                remoteControl = RemoteControlProxy.Register();
                if (remoteControl != null)
                {
                    Logger.Debug("Tasque remote control active.");
                }
                else
                {
                    // If Tasque is already running, open the tasks window
                    // so the user gets some sort of feedback when they
                    // attempt to run Tasque again.
                    RemoteControl remote = null;
                    try {
                        remote = RemoteControlProxy.GetInstance();
                        remote.ShowTasks();
                    } catch {}

                    Logger.Debug("Tasque is already running.  Exiting...");
                    System.Environment.Exit(0);
                }
            } catch (Exception e) {
                Logger.Debug("Tasque remote control disabled (DBus exception): {0}",
                             e.Message);
            }
#endif

            string potentialBackendClassName = null;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args [i])
                {
                case "--quiet":
                    quietStart = true;
                    Logger.Debug("Starting quietly");
                    break;

                case "--backend":
                    if ((i + 1 < args.Length) &&
                        !string.IsNullOrEmpty(args [i + 1]) &&
                        args [i + 1] [0] != '-')
                    {
                        potentialBackendClassName = args [++i];
                    }                     // TODO: Else, print usage
                    break;

                default:
                    // Support old argument behavior
                    if (!string.IsNullOrEmpty(args [i]))
                    {
                        potentialBackendClassName = args [i];
                    }
                    break;
                }
            }

            // See if a specific backend is specified
            if (potentialBackendClassName != null)
            {
                Logger.Debug("Backend specified: " +
                             potentialBackendClassName);

                customBackend = null;
                Assembly asm = Assembly.GetCallingAssembly();
                try {
                    customBackend = (IBackend)
                                    asm.CreateInstance(potentialBackendClassName);
                } catch (Exception e) {
                    Logger.Warn("Backend specified on args not found: {0}\n\t{1}",
                                potentialBackendClassName, e.Message);
                }
            }

            // Discover all available backends
            LoadAvailableBackends();

            GLib.Idle.Add(InitializeIdle);
            GLib.Timeout.Add(60000, CheckForDaySwitch);
        }