예제 #1
0
        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = String.Format(Catalog.GetString("Edit Icon for Tag {0}"), t.Name);

            preview_pixbuf = t.Icon;
            Cms.Profile screen_profile;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new [] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Catalog.GetString("Select Photo from file"),
                                                               Gtk.FileChooserAction.Open);

            external_photo_chooser.Filter = new FileFilter();
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = (double)query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup = String.Format(Catalog.GetString(
                                                            "\n<b>From Photo</b>\n" +
                                                            " You can use one of your library photos as an icon for this tag.\n" +
                                                            " However, first you must have at least one photo associated\n" +
                                                            " with this tag. Please tag a photo as '{0}' and return here\n" +
                                                            " to use it as an icon."), t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store);
            icon_view.PixbufColumn      = 1;
            icon_view.SelectionMode     = SelectionMode.Single;
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            DelayedOperation fill_delay = new DelayedOperation(FillIconView);

            fill_delay.Start();
        }
예제 #2
0
 public Photo [] Query(Tag [] tags, string extra_condition, DateRange range, RollSet importidrange)
 {
     return(Query(OrTerm.FromTags(tags), extra_condition, range, importidrange));
 }
예제 #3
0
        bool ConstructQuery(Term parent, int depth, string txt, bool negated)
        {
            if (string.IsNullOrEmpty(txt))
            {
                return(true);
            }

            string indent = string.Format($"{{0,{depth * 2}}}", " ");

            //Log.DebugFormat (indent + "Have text: {0}", txt);

            // Match the query the user typed against our regular expression
            var match = term_regex.Match(txt);

            if (!match.Success)
            {
                //Log.Debug (indent + "Failed to match.");
                return(false);
            }

            bool   op_valid = true;
            string op       = string.Empty;

            // For the moment at least we don't support operator precedence, so we require
            // that only a single operator is used for any given term unless it is made unambiguous
            // by using parenthesis.
            foreach (Capture capture in match.Groups["Ops"].Captures)
            {
                if (op == string.Empty)
                {
                    op = capture.Value;
                }
                else if (op != capture.Value)
                {
                    op_valid = false;
                    break;
                }
            }

            if (!op_valid)
            {
                Log.Information(indent + "Ambiguous operator sequence.  Use parenthesis to explicitly define evaluation order.");
                return(false);
            }

            if (match.Groups ["Terms"].Captures.Count == 1 && match.Groups["NotTerm"].Captures.Count != 1)
            {
                //Log.DebugFormat (indent + "Unbreakable term: {0}", match.Groups ["Terms"].Captures [0]);
                string literal;
                bool   is_negated = false;
                if (match.Groups ["NotTag"].Captures.Count == 1)
                {
                    literal    = match.Groups ["NotTag"].Captures [0].Value;
                    is_negated = true;
                }
                else
                {
                    literal = match.Groups ["Terms"].Captures [0].Value;
                }

                is_negated = is_negated || negated;

                var tag = App.Instance.Database.Tags.GetTagByName(literal);

                // New OR term so we can match against both tag and text search
                parent = new OrTerm(parent, null);

                // If the literal is the name of a tag, include it in the OR
                //AbstractLiteral term = null;
                if (tag != null)
                {
                    new Literal(parent, tag, null);
                }

                // Always include the literal text in the search (path, comment, etc)
                new TextLiteral(parent, literal);

                // If the term was negated, negate the OR parent term
                if (is_negated)
                {
                    parent = parent.Invert(true);
                }

                if (RootTerm == null)
                {
                    RootTerm = parent;
                }

                return(true);
            }
            else
            {
                Term us = null;
                if (op != null && op != string.Empty)
                {
                    us = Term.TermFromOperator(op, parent, null);
                    if (RootTerm == null)
                    {
                        RootTerm = us;
                    }
                }

                foreach (Capture capture in match.Groups["Term"].Captures)
                {
                    string subterm = capture.Value.Trim();

                    if (string.IsNullOrEmpty(subterm))
                    {
                        continue;
                    }

                    // Strip leading/trailing parens
                    if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')')
                    {
                        subterm = subterm.Remove(subterm.Length - 1, 1);
                        subterm = subterm.Remove(0, 1);
                    }

                    //Log.DebugFormat (indent + "Breaking subterm apart: {0}", subterm);

                    if (!ConstructQuery(us, depth + 1, subterm, negated))
                    {
                        return(false);
                    }
                }

                foreach (Capture capture in match.Groups["NotTerm"].Captures)
                {
                    string subterm = capture.Value.Trim();

                    if (string.IsNullOrEmpty(subterm))
                    {
                        continue;
                    }

                    // Strip leading/trailing parens
                    if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')')
                    {
                        subterm = subterm.Remove(subterm.Length - 1, 1);
                        subterm = subterm.Remove(0, 1);
                    }

                    //Log.DebugFormat (indent + "Breaking not subterm apart: {0}", subterm);

                    if (!ConstructQuery(us, depth + 1, subterm, true))
                    {
                        return(false);
                    }
                }

                if (negated && us != null)
                {
                    if (us == RootTerm)
                    {
                        RootTerm = us.Invert(false);
                    }
                    else
                    {
                        us.Invert(false);
                    }
                }

                return(true);
            }
        }
예제 #4
0
#pragma warning restore 649

        public EditTagIconDialog(Db db, Tag t, Gtk.Window parent_window) : base("EditTagIconDialog.ui", "edit_tag_icon_dialog")
        {
            TransientFor = parent_window;
            Title        = Strings.EditIconForTagName(t.Name);

            // FIXME, Icon
            //preview_pixbuf = t.Icon;
            if (preview_pixbuf != null && ColorManagement.Profiles.TryGetValue(Preferences.Get <string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out var screen_profile))
            {
                preview_image.Pixbuf = preview_pixbuf.Copy();
                ColorManagement.ApplyProfile(preview_image.Pixbuf, screen_profile);
            }
            else
            {
                preview_image.Pixbuf = preview_pixbuf;
            }

            query = new PhotoQuery(db.Photos);

            if (db.Tags.Hidden != null)
            {
                query.Terms = OrTerm.FromTags(new[] { t });
            }
            else
            {
                query.Terms = new Literal(t);
            }

            image_view = new PhotoImageView(query)
            {
                CropHelpers = false
            };
            image_view.SelectionXyRatio  = 1.0;
            image_view.SelectionChanged += HandleSelectionChanged;
            image_view.PhotoChanged     += HandlePhotoChanged;

            external_photo_chooser = new Gtk.FileChooserButton(Strings.SelectPhotoFromFile, Gtk.FileChooserAction.Open)
            {
                Filter = new FileFilter()
            };
            external_photo_chooser.Filter.AddPixbufFormats();
            external_photo_chooser.LocalOnly = false;
            external_photo_chooser_hbox.PackStart(external_photo_chooser);
            external_photo_chooser.Show();
            external_photo_chooser.SelectionChanged += HandleExternalFileSelectionChanged;

            photo_scrolled_window.Add(image_view);

            if (query.Count > 0)
            {
                photo_spin_button.Wrap                     = true;
                photo_spin_button.Adjustment.Lower         = 1.0;
                photo_spin_button.Adjustment.Upper         = query.Count;
                photo_spin_button.Adjustment.StepIncrement = 1.0;
                photo_spin_button.ValueChanged            += HandleSpinButtonChanged;

                image_view.Item.Index = 0;
            }
            else
            {
                from_photo_label.Markup       = string.Format($"\n<b>{Strings.FromPhoto}</b>\n{Strings.TagFromPhotoLabelMessage}", t.Name);
                photo_scrolled_window.Visible = false;
                photo_label.Visible           = false;
                photo_spin_button.Visible     = false;
            }

            icon_store = new ListStore(typeof(string), typeof(Gdk.Pixbuf));

            icon_view = new Gtk.IconView(icon_store)
            {
                PixbufColumn  = 1,
                SelectionMode = SelectionMode.Single
            };
            icon_view.SelectionChanged += HandleIconSelectionChanged;

            icon_scrolled_window.Add(icon_view);

            icon_view.Show();

            image_view.Show();

            //var fill_delay = new DelayedOperation (FillIconView);
            //fill_delay.Start ();
        }