コード例 #1
0
ファイル: Import.cs プロジェクト: balihb/basenji
 private void OnImportCompleted(object sender, ImportCompletedEventArgs e)
 {
     try {
         Application.Invoke(delegate {
             if (e.Error != null)
             {
                 if (e.Error is System.IO.FileNotFoundException)
                 {
                     MsgDialog.ShowError(this, S._("Import failed"),
                                         S._("Database not found."));
                 }
                 progress.Text = S._("Import failed!");
             }
             else if (e.Cancelled)
             {
                 progress.Text = S._("Import aborted.");
             }
             else
             {
                 progress.Text = S._("Import completed successfully.");
                 OnVolumesImported();
             }
         });
     } finally {
         Application.Invoke(delegate {
             btnClose.Sensitive   = true;
             fcDatabase.Sensitive = true;
             btnImport.Sensitive  = true;
             btnImport.Label      = LBL_IMPORT;
         });
     }
 }
コード例 #2
0
ファイル: Import.cs プロジェクト: balihb/basenji
 private void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
 {
     if (import != null && import.IsBusy)
     {
         MsgDialog.ShowError(this, S._("Import in progress"),
                             S._("You must stop the import before closing this window."));
         args.RetVal = true;
     }
 }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: balihb/basenji
        private void AddVolume()
        {
            PlatformIO.DriveInfo drive;

            if (App.Settings.ScannerDevice.Length > 0)
            {
                try {
                    drive = PlatformIO.DriveInfo.FromDevice(App.Settings.ScannerDevice);
                } catch (ArgumentException e) {                // e.g. drive not found
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("An error occured while accessing drive {0}:\n{1}"),
                                        App.Settings.ScannerDevice,
                                        e.Message);

                    return;
                }
            }
            else
            {
                DriveSelection ds     = new DriveSelection();
                ResponseType   result = (ResponseType)ds.Run();
                ds.Destroy();

                if (result != ResponseType.Ok)
                {
                    return;
                }

                drive = ds.SelectedDrive;
            }

            if (!drive.IsReady)
            {
                MsgDialog.ShowError(this,
                                    S._("Error"),
                                    S._("Drive {0} is not ready."),
                                    drive.Device);                 // e.g. no volume inserted

                return;
            }

            if (!drive.IsMounted && !drive.HasAudioCdVolume)
            {
                MsgDialog.ShowError(this,
                                    S._("Error"),
                                    S._("Drive {0} is neither mounted nor does it contain an audio cd."),
                                    drive.Device);

                return;
            }

            VolumeScanner vs = new VolumeScanner(database, drive);

            AddNewVolumeAddedEventHandler(vs);
        }
コード例 #4
0
ファイル: ObjectProperties.cs プロジェクト: balihb/basenji
 private bool SaveAndClose()
 {
     try {
         objEditor.Save();
         this.Destroy();
     } catch (ValidationException e) {
         MsgDialog.ShowError(this, S._("Invalid data"), string.Format(S._("\"{0}\" is {1}.\n\nExpected format: {2}\nPlease correct or remove the data you entered."), e.WidgetName, e.Message, e.ExpectedFormat));
         return(false);
     }
     return(true);
 }
コード例 #5
0
 private void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
 {
     if (!scanCompleted)
     {
         MsgDialog.ShowError(this, S._("Scan in progress"), S._("You must stop scanning before closing this window."));
         args.RetVal = true;
     }
     else
     {
         bool cancel = !SaveAndClose();
         args.RetVal = cancel;
     }
 }
コード例 #6
0
ファイル: MainWindow.cs プロジェクト: balihb/basenji
        private void OnActRecentlyUsedActivated(object sender, System.EventArgs args)
        {
            RecentAction act  = (RecentAction)sender;
            string       path = act.CurrentUri.Replace("file://", string.Empty);

            if (!File.Exists(path))
            {
                MsgDialog.ShowError(this, S._("Error"), S._("Database '{0}' not found."), path);
                return;
            }

            // volumes list will be refreshed asynchronously
            OpenDB(path, false, true, null);
        }
コード例 #7
0
        private bool SaveAndClose()
        {
            try {
                if (scanner.ScanSucceeded)
                {
                    // SaveTo() may throw a ValidationException.
                    // Note: The volumeditor has either been filled on scanner start manually
                    // (no volume loaded) or an existing volume has been loaded into it
                    // (via the public VolumeEditor property or via volEditor.Load() on scan completion).
                    volEditor.SaveTo(newVolume);
                    SaveLog(newVolume.VolumeID);
                    OnNewVolumeAdded(newVolume);
                }

                this.Destroy();

                if (scanner != null)
                {
                    scanner.Dispose();
                }

                if (mdps != null)
                {
                    foreach (var m in mdps)
                    {
                        m.Dispose();
                    }
                }
            } catch (ValidationException e) {
                MsgDialog.ShowError(this, S._("Invalid data"),
                                    string.Format(S._("\"{0}\" is {1}.\n\nExpected format: {2}\nPlease correct or remove the data you entered."),
                                                  e.WidgetName, e.Message, e.ExpectedFormat));
                return(false);
            }
            return(true);
        }
コード例 #8
0
ファイル: MainWindow.cs プロジェクト: balihb/basenji
        private void SelectExistingDB()
        {
            string       db;
            ResponseType result = FileDialog.Show(FileChooserAction.Open,
                                                  this,
                                                  S._("Please select a database"),
                                                  out db);

            if (result == ResponseType.Ok && db.Length > 0)
            {
                // check if the file existst before calling OpenDB()
                // so the currently loaded db won't be unloaded.
                if (!File.Exists(db))
                {
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("Database not found."));
                }
                else
                {
                    OpenDB(db, false, true, null);
                }
            }
        }
コード例 #9
0
ファイル: MainWindow.cs プロジェクト: balihb/basenji
        public MainWindow(string dbPath)
        {
            recentManager = RecentManager.Default;

            // retrieve the sort property from settings
            // (from default settings if the settings file does not exist yet)
            Widgets.VolumeSortProperty sp;
            bool desc;

            GetVolumeSortProperty(out sp, out desc);

            BuildGui();

            windowDeleted = false;
            lastSuccessfulSearchCriteria = null;

            SetWindowTitle(null);
            EnableGui(false);

            // set the volumeview's sort property
            // (before filling it with volumes)
            tvVolumes.SetSortProperty(sp, desc);

            // create default db on first startup
            if (!App.Settings.SettingsFileExists())
            {
                // creates (or opens existing) default db and if successful,
                // sets the db path and calls settings.Save()
                OpenOrCreateDefaultDB(false);
                return;
            }

            if (dbPath != null)
            {
                if (!File.Exists(dbPath))
                {
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("Database '{0}' not found."),
                                        dbPath);
                }
                else
                {
                    // volumes list will be refreshed asynchronously
                    OpenDB(dbPath, false, true, null);
                }

                return;
            }

            // reopen recent database
            dbPath = App.Settings.MostRecentDBPath;
            if (App.Settings.OpenMostRecentDB && dbPath.Length > 0)
            {
                if (!File.Exists(dbPath))
                {
                    MsgDialog.ShowError(this,
                                        S._("Error"),
                                        S._("Database '{0}' not found."),
                                        dbPath);

                    // clear path so the error won't occur again on next startup
                    App.Settings.MostRecentDBPath = string.Empty;
                    App.Settings.Save();
                }
                else
                {
                    // volumes list will be refreshed asynchronously
                    OpenDB(dbPath, false, true, null);
                }
            }
        }
コード例 #10
0
ファイル: MainWindow.cs プロジェクト: balihb/basenji
        private void OpenDB(string path, bool createNew, bool loadAsync, System.Action onsuccess)
        {
            EnableGui(false);             // will be re-enabled after opening AND loading has been completed successfully
            SetWindowTitle(null);

            // clear views
            tvVolumes.Clear();
            tvItems.Clear();
            itemInfo.Clear();
            itemInfo.Hide();

            if (database != null)
            {
                database.Close();
            }

            lastSuccessfulSearchCriteria = null;

            try {
                database = new VolumeDatabase(path, createNew);
                database.SearchItemResultsLimit = App.SEARCH_RESULTS_LIMIT;
            } catch (UnsupportedDbVersionException) {
                MsgDialog.ShowError(this,
                                    S._("Unsupported database version"),
                                    S._("This database version is not supported."));
                return;
            }

            // load volumes

            Action <Volume[]> updateGui = (Volume[] volumes) => {
                tvVolumes.Fill(volumes);

                // select first volume

                /*
                 * // this clearly harms startup time.
                 * TreeIter iter;
                 * if (tvVolumes.Model.GetIterFirst(out iter))
                 *      tvVolumes.Selection.SelectIter(iter);
                 */

                EnableGui(true);
                SetWindowTitle(path);
                SetTempStatus(string.Format(S._("{0} volumes loaded."), volumes.Length));

                recentManager.AddFull("file://" + path, recentData);

                App.Settings.MostRecentDBPath = path;
                App.Settings.Save();

                if (onsuccess != null)
                {
                    onsuccess();                      // must be called on the gui thread
                }
            };

            if (loadAsync)
            {
                // delegate that will be called
                // when asynchronous volume loading (searching) has been finished.
                AsyncCallback cb = (IAsyncResult ar) => {
                    Volume[] volumes;

                    try {
                        volumes = database.EndSearchVolume(ar);
                    } catch (Exception ex) {
                        Application.Invoke(delegate {
                            SetStatus(string.Format(S._("An error occured while loading the volume list: {0}"),
                                                    ex.Message));
                        });
                        return;
                    }

                    Application.Invoke(delegate {
                        updateGui(volumes);
                    });
                };

                database.BeginSearchVolume(cb, null);                 // returns immediately
            }
            else
            {
                Volume[] volumes = database.SearchVolume();
                updateGui(volumes);
            }
        }