~ubuntu-branches/ubuntu/quantal/shotwell/quantal

« back to all changes in this revision

Viewing changes to src/Dialogs.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-02-21 13:52:58 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: package-import@ubuntu.com-20120221135258-ao9jiib5qicomq7q
Tags: upstream-0.11.92
Import upstream version 0.11.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright 2009-2011 Yorba Foundation
 
1
/* Copyright 2009-2012 Yorba Foundation
2
2
 *
3
3
 * This software is licensed under the GNU LGPL (version 2.1 or later).
4
4
 * See the COPYING file in this distribution. 
49
49
namespace ExportUI {
50
50
private static File current_export_dir = null;
51
51
 
52
 
// Dummy function for suppressing 'could not stat file' errors
53
 
// generated when saving into a previously non-existant file -
54
 
// please see https://bugzilla.gnome.org/show_bug.cgi?id=662814
55
 
// This should be removed once GTK 3.4 is widely available, as
56
 
// it is slated to correct the problem.
57
 
public void suppress_warnings(string? log_domain, LogLevelFlags log_levels, string message) {
58
 
    // do nothing.
59
 
}
60
 
 
61
52
public File? choose_file(string current_file_basename) {
62
53
    if (current_export_dir == null)
63
54
        current_export_dir = File.new_for_path(Environment.get_home_dir());
435
426
        ok_button.sensitive = (pixels_entry.get_text_length() > 0) && (int.parse(pixels_entry.get_text()) > 0);
436
427
    }
437
428
    
438
 
    private void on_pixels_insert_text(string text, int length, void *position) {
 
429
    private void on_pixels_insert_text(string text, int length, ref int position) {
439
430
        // This is necessary because SignalHandler.block_by_func() is not properly bound
440
431
        if (in_insert)
441
432
            return;
454
445
        }
455
446
        
456
447
        if (new_text.length > 0)
457
 
            pixels_entry.insert_text(new_text, (int) new_text.length, position);
 
448
            pixels_entry.insert_text(new_text, (int) new_text.length, ref position);
458
449
        
459
450
        Signal.stop_emission_by_name(pixels_entry, "insert-text");
460
451
        
1621
1612
        Gee.Collection<Tag> terminal_tags = Tag.get_terminal_tags(source_tags);
1622
1613
        
1623
1614
        Gee.SortedSet<string> tag_basenames = new Gee.TreeSet<string>();
1624
 
                foreach (Tag tag in terminal_tags)
 
1615
        foreach (Tag tag in terminal_tags)
1625
1616
            tag_basenames.add(HierarchicalTagUtilities.get_basename(tag.get_path()));
1626
1617
        
1627
1618
        string? text = null;
1665
1656
    
1666
1657
}
1667
1658
 
 
1659
public interface WelcomeServiceEntry : GLib.Object {
 
1660
    public abstract string get_service_name();
 
1661
    
 
1662
    public abstract void execute();
 
1663
}
 
1664
 
1668
1665
public class WelcomeDialog : Gtk.Dialog {
1669
1666
    Gtk.CheckButton hide_button;
1670
 
    Gtk.CheckButton? fspot_import_check = null;
1671
1667
    Gtk.CheckButton? system_pictures_import_check = null;
1672
 
 
 
1668
    Gtk.CheckButton[] external_import_checks = new Gtk.CheckButton[0];
 
1669
    WelcomeServiceEntry[] external_import_entries = new WelcomeServiceEntry[0];
 
1670
    Gtk.Label secondary_text;
 
1671
    Gtk.Label instruction_header;
 
1672
    Gtk.VBox import_content;
 
1673
    Gtk.VBox import_action_checkbox_packer;
 
1674
    Gtk.VBox external_import_action_checkbox_packer;
 
1675
    Spit.DataImports.WelcomeImportMetaHost import_meta_host;
 
1676
    bool import_content_already_installed = false;
 
1677
    
1673
1678
    public WelcomeDialog(Gtk.Window owner) {
1674
 
        bool show_fspot_import = is_fspot_import_possible();
 
1679
        import_meta_host = new Spit.DataImports.WelcomeImportMetaHost(this);
1675
1680
        bool show_system_pictures_import = is_system_pictures_import_possible();
1676
1681
        Gtk.Widget ok_button = add_button(Gtk.Stock.OK, Gtk.ResponseType.OK);
1677
1682
        set_title(_("Welcome!"));
1683
1688
        primary_text.set_markup(
1684
1689
            "<span size=\"large\" weight=\"bold\">%s</span>".printf(_("Welcome to Shotwell!")));
1685
1690
        primary_text.set_alignment(0, 0.5f);
1686
 
        Gtk.Label secondary_text = new Gtk.Label("");
1687
 
        if (!(show_fspot_import || show_system_pictures_import)) {
1688
 
            secondary_text.set_markup("<span weight=\"normal\">%s</span>".printf(
1689
 
                _("To get started, import photos in any of these ways:")));
1690
 
        }
 
1691
        secondary_text = new Gtk.Label("");
 
1692
        secondary_text.set_markup("<span weight=\"normal\">%s</span>".printf(
 
1693
            _("To get started, import photos in any of these ways:")));
1691
1694
        secondary_text.set_alignment(0, 0.5f);
1692
1695
        Gtk.Image image = new Gtk.Image.from_pixbuf(Resources.get_icon(Resources.ICON_APP, 50));
1693
1696
        
1694
 
        Gtk.Widget? header_text = null;
1695
 
        if (show_fspot_import || show_system_pictures_import) {
1696
 
            header_text = primary_text;
1697
 
        } else {
1698
 
            header_text = new Gtk.VBox(false, 0);
1699
 
            
1700
 
            ((Gtk.VBox) header_text).pack_start(primary_text, false, false, 5);
1701
 
            ((Gtk.VBox) header_text).pack_start(secondary_text, false, false, 0);
1702
 
        }
 
1697
        Gtk.VBox header_text = new Gtk.VBox(false, 0);
 
1698
        header_text.pack_start(primary_text, false, false, 5);
 
1699
        header_text.pack_start(secondary_text, false, false, 0);
1703
1700
 
1704
1701
        Gtk.HBox header_content = new Gtk.HBox(false, 12);
1705
1702
        header_content.pack_start(image, false, false, 0);
1706
1703
        header_content.pack_start(header_text, false, false, 0);
1707
1704
 
1708
1705
        Gtk.Label instructions = new Gtk.Label("");
1709
 
        string indent_prefix = (show_fspot_import || show_system_pictures_import) ? "   " : "";
 
1706
        string indent_prefix = "   "; // we can't tell what the indent prefix is going to be so assume we need one
1710
1707
        instructions.set_markup(((indent_prefix + "&#8226; %s\n") + (indent_prefix + "&#8226; %s\n")
1711
1708
            + (indent_prefix + "&#8226; %s")).printf(
1712
1709
            _("Choose <span weight=\"bold\">File %s Import From Folder</span>").printf("▸"),
1714
1711
            _("Connect a camera to your computer and import")));
1715
1712
        instructions.set_alignment(0, 0.5f);
1716
1713
        
1717
 
        Gtk.VBox? import_action_checkbox_packer = null;
1718
 
        if (show_fspot_import || show_system_pictures_import) {
1719
 
            import_action_checkbox_packer = new Gtk.VBox(false, 2);
1720
 
            
1721
 
            if (show_fspot_import) {
1722
 
                fspot_import_check = new Gtk.CheckButton.with_mnemonic(
1723
 
                    _("Import photos from your _F-Spot library"));
1724
 
                import_action_checkbox_packer.add(fspot_import_check);
1725
 
                fspot_import_check.set_active(true);
1726
 
            }
1727
 
            
1728
 
            if (show_system_pictures_import) {
1729
 
                system_pictures_import_check = new Gtk.CheckButton.with_mnemonic(
1730
 
                    _("_Import photos from your %s folder").printf(
1731
 
                    get_display_pathname(AppDirs.get_import_dir())));
1732
 
                import_action_checkbox_packer.add(system_pictures_import_check);
1733
 
                system_pictures_import_check.set_active(true);
1734
 
            }
1735
 
        }
1736
 
        
1737
 
        Gtk.Label? instruction_header = null;
1738
 
        if (show_fspot_import || show_system_pictures_import) {
1739
 
            instruction_header = new Gtk.Label(
1740
 
                _("You can also import photos in any of these ways:"));
1741
 
            instruction_header.set_alignment(0.0f, 0.5f);
1742
 
        }
 
1714
        import_action_checkbox_packer = new Gtk.VBox(false, 2);
 
1715
        
 
1716
        external_import_action_checkbox_packer = new Gtk.VBox(false, 2);
 
1717
        import_action_checkbox_packer.add(external_import_action_checkbox_packer);
 
1718
        
 
1719
        if (show_system_pictures_import) {
 
1720
            system_pictures_import_check = new Gtk.CheckButton.with_mnemonic(
 
1721
                _("_Import photos from your %s folder").printf(
 
1722
                get_display_pathname(AppDirs.get_import_dir())));
 
1723
            import_action_checkbox_packer.add(system_pictures_import_check);
 
1724
            system_pictures_import_check.set_active(true);
 
1725
        }
 
1726
        
 
1727
        instruction_header = new Gtk.Label(
 
1728
            _("You can also import photos in any of these ways:"));
 
1729
        instruction_header.set_alignment(0.0f, 0.5f);
 
1730
        instruction_header.set_margin_top(20);
1743
1731
        
1744
1732
        Gtk.VBox content = new Gtk.VBox(false, 16);
1745
1733
        content.pack_start(header_content, true, true, 0);
1746
 
        if (show_fspot_import || show_system_pictures_import) {
1747
 
            content.add(import_action_checkbox_packer);
1748
 
            content.add(instruction_header);
1749
 
        }
 
1734
        import_content = new Gtk.VBox(false, 2);
 
1735
        content.add(import_content);
 
1736
        //content.add(import_action_checkbox_packer);
 
1737
        //content.add(instruction_header);
1750
1738
        content.pack_start(instructions, false, false, 0);
1751
1739
 
1752
1740
        hide_button = new Gtk.CheckButton.with_mnemonic(_("_Don't show this message again"));
1759
1747
 
1760
1748
        ((Gtk.Box) get_content_area()).pack_start(alignment, false, false, 0);
1761
1749
 
1762
 
                set_has_resize_grip(false);
 
1750
        set_has_resize_grip(false);
1763
1751
        
1764
1752
        ok_button.grab_focus();
 
1753
        
 
1754
        install_import_content();
 
1755
        
 
1756
        import_meta_host.start();
 
1757
    }
 
1758
    
 
1759
    private void install_import_content() {
 
1760
        if (
 
1761
            (external_import_checks.length > 0 || system_pictures_import_check != null) &&
 
1762
            (import_content_already_installed == false)
 
1763
        ) {
 
1764
            secondary_text.set_markup("");
 
1765
            import_content.add(import_action_checkbox_packer);
 
1766
            import_content.add(instruction_header);
 
1767
            import_content_already_installed = true;
 
1768
        }
 
1769
    }
 
1770
    
 
1771
    public void install_service_entry(WelcomeServiceEntry entry) {
 
1772
        debug("WelcomeDialog: Installing service entry for %s".printf(entry.get_service_name()));
 
1773
        external_import_entries += entry;
 
1774
        Gtk.CheckButton entry_check = new Gtk.CheckButton.with_label(
 
1775
            _("Import photos from your %s library").printf(entry.get_service_name()));
 
1776
        external_import_checks += entry_check;
 
1777
        entry_check.set_active(true);
 
1778
        external_import_action_checkbox_packer.add(entry_check);
 
1779
        install_import_content();
1765
1780
    }
1766
1781
 
1767
 
    public bool execute(out bool do_fspot_import, out bool do_system_pictures_import) {
 
1782
    public bool execute(out WelcomeServiceEntry[] selected_import_entries, out bool do_system_pictures_import) {
1768
1783
        show_all();
1769
1784
 
1770
1785
        bool ok = (run() == Gtk.ResponseType.OK);
1773
1788
        if (ok)
1774
1789
            show_dialog = !hide_button.get_active();
1775
1790
        
1776
 
        do_fspot_import = (fspot_import_check != null) ? fspot_import_check.get_active() : false;
 
1791
        // Use a temporary variable as += cannot be used on parameters
 
1792
        WelcomeServiceEntry[] result = new WelcomeServiceEntry[0];
 
1793
        for (int i = 0; i < external_import_entries.length; i++) {
 
1794
            if (external_import_checks[i].get_active() == true)
 
1795
                result += external_import_entries[i];
 
1796
        }
 
1797
        selected_import_entries = result;
1777
1798
        do_system_pictures_import = 
1778
1799
            (system_pictures_import_check != null) ? system_pictures_import_check.get_active() : false;
1779
1800
 
1798
1819
            return false;
1799
1820
        }
1800
1821
    }
1801
 
    
1802
 
    private static bool is_fspot_import_possible() {
1803
 
        return AlienDb.FSpot.FSpotDatabaseDriver.is_available();
1804
 
    }
1805
1822
}
1806
1823
 
1807
1824
public class PreferencesDialog {
2089
2106
    }
2090
2107
    
2091
2108
    private void on_value_changed() {
2092
 
        set_background_color(bg_color_adjustment.get_upper() - bg_color_adjustment.get_value());
 
2109
        set_background_color((double)(bg_color_adjustment.get_upper() - 
 
2110
            bg_color_adjustment.get_value()) / 65535.0);
2093
2111
    }
2094
2112
 
2095
2113
    private bool on_bg_color_reset(Gdk.EventButton event) {
2148
2166
    }
2149
2167
 
2150
2168
    private void set_background_color(double bg_color_value) {
2151
 
        Config.Facade.get_instance().set_bg_color(to_grayscale((uint16) bg_color_value));
 
2169
        Config.Facade.get_instance().set_bg_color(to_grayscale(bg_color_value));
2152
2170
    }
2153
2171
 
2154
 
    private Gdk.Color to_grayscale(uint16 color_value) {
2155
 
        Gdk.Color color = Gdk.Color();
 
2172
    private Gdk.RGBA to_grayscale(double color_value) {
 
2173
        Gdk.RGBA color = Gdk.RGBA();
2156
2174
        
2157
2175
        color.red = color_value;
2158
2176
        color.green = color_value;
2159
2177
        color.blue = color_value;
 
2178
        color.alpha = 1.0;
2160
2179
        
2161
2180
        return color;
2162
2181
    }