Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some terminal warnings #791

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/Views/CollectionPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class CollectionPage : MediaPage {
private CollectionSearchViewFilter search_filter = new CollectionSearchViewFilter ();
private Gtk.ToggleButton? enhance_button = null;
private Gtk.Menu item_context_menu;
private Gtk.Menu contractor_menu;
private Gtk.Menu contractor_submenu;
private Gtk.Button rotate_button;
private Gtk.Button flip_button;

Expand Down Expand Up @@ -196,14 +196,6 @@ public abstract class CollectionPage : MediaPage {
export_action.bind_property ("sensitive", export_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
export_menu_item.activate.connect (() => export_action.activate ());

var wallpaper_menuitem = new Gtk.MenuItem.with_label (_("Set as Wallpaper")) {
action_name = AppWindow.ACTION_PREFIX + AppWindow.ACTION_SET_WALLPAPER
};

var contractor_menu_item = new Gtk.MenuItem.with_mnemonic (_("Other Actions"));
contractor_menu = new Gtk.Menu ();
contractor_menu_item.set_submenu (contractor_menu);

var remove_menu_item = new Gtk.MenuItem.with_mnemonic (Resources.REMOVE_FROM_LIBRARY_MENU);
var remove_action = get_action ("RemoveFromLibrary");
remove_action.bind_property ("sensitive", remove_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
Expand All @@ -214,9 +206,23 @@ public abstract class CollectionPage : MediaPage {
trash_action.bind_property ("sensitive", trash_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
trash_menu_item.activate.connect (() => trash_action.activate ());

contractor_menu.add (print_menu_item);
contractor_menu.add (export_menu_item);
contractor_menu.add (wallpaper_menuitem);
var contractor_menu_item = new Gtk.MenuItem.with_mnemonic (_("Other Actions"));
contractor_submenu = new Gtk.Menu ();
contractor_menu_item.set_submenu (contractor_submenu);
contractor_submenu.add (print_menu_item);
contractor_submenu.add (export_menu_item);

var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) {
var file = ((Photo) source).get_file ();
if (file != null) {
var wallpaper_menuitem = new Gtk.MenuItem.with_label (_("Set as Wallpaper")) {
action_name = AppWindow.ACTION_PREFIX + AppWindow.ACTION_SET_WALLPAPER,
action_target = new Variant.string (file.get_uri ())
};
contractor_submenu.add (wallpaper_menuitem);
}
}

item_context_menu.add (copy_images_menu_item);
item_context_menu.add (adjust_datetime_menu_item);
Expand All @@ -240,15 +246,9 @@ public abstract class CollectionPage : MediaPage {
item_context_menu.add (remove_menu_item);
item_context_menu.add (trash_menu_item);
item_context_menu.show_all ();

var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) {
var file = (((Photo) source).get_file ());
wallpaper_menuitem.action_target = new Variant.string (file.get_uri ());
}
}

populate_contractor_menu (contractor_menu);
populate_contractor_menu (contractor_submenu);
return item_context_menu;
}

Expand Down
36 changes: 17 additions & 19 deletions src/Views/LibraryPhotoPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LibraryPhotoPage : EditingHostPage {
private CollectionPage? return_page = null;
private bool return_to_collection_on_release = false;
private LibraryPhotoPageViewFilter filter = new LibraryPhotoPageViewFilter ();
private Gtk.Menu contractor_menu;
private Gtk.Menu contractor_submenu;
private Gtk.Menu item_context_menu;

public LibraryPhotoPage () {
Expand Down Expand Up @@ -562,14 +562,22 @@ public class LibraryPhotoPage : EditingHostPage {
export_action.bind_property ("sensitive", export_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
export_menu_item.activate.connect (() => export_action.activate ());

var wallpaper_menuitem = new Gtk.MenuItem.with_label (_("Set as Wallpaper")) {
action_name = AppWindow.ACTION_PREFIX + AppWindow.ACTION_SET_WALLPAPER
};

var contractor_menu_item = new Gtk.MenuItem.with_mnemonic (_("Other Actions"));
contractor_menu = new Gtk.Menu ();
contractor_menu_item.set_submenu (contractor_menu);

contractor_submenu = new Gtk.Menu ();
contractor_menu_item.set_submenu (contractor_submenu);
contractor_submenu.add (print_menu_item);
contractor_submenu.add (export_menu_item);
var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) { // Cannot set other media as wallpaper
var file = ((Photo)source).get_file ();
if (file != null) {
var wallpaper_menuitem = new Gtk.MenuItem.with_label (_("Set as Wallpaper")) {
action_name = AppWindow.ACTION_PREFIX + AppWindow.ACTION_SET_WALLPAPER,
action_target = new Variant.string (file.get_uri ())
};
contractor_submenu.add (wallpaper_menuitem);
}
}
var remove_menu_item = new Gtk.MenuItem.with_mnemonic (Resources.REMOVE_FROM_LIBRARY_MENU);
var remove_action = get_action ("RemoveFromLibrary");
remove_action.bind_property ("sensitive", remove_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
Expand All @@ -580,10 +588,6 @@ public class LibraryPhotoPage : EditingHostPage {
trash_action.bind_property ("sensitive", trash_menu_item, "sensitive", BindingFlags.SYNC_CREATE);
trash_menu_item.activate.connect (() => trash_action.activate ());

contractor_menu.add (print_menu_item);
contractor_menu.add (export_menu_item);
contractor_menu.add (wallpaper_menuitem);

item_context_menu.add (adjust_datetime_menu_item);
item_context_menu.add (new Gtk.SeparatorMenuItem ());
item_context_menu.add (copy_image_menu_item);
Expand All @@ -606,15 +610,9 @@ public class LibraryPhotoPage : EditingHostPage {
item_context_menu.add (remove_menu_item);
item_context_menu.add (trash_menu_item);
item_context_menu.show_all ();

var source = get_view ().get_selected_at (0).source;
if (source != null && source is Photo) {
var file = get_photo ().get_file ();
wallpaper_menuitem.action_target = new Variant.string (file.get_uri ());
}
}

populate_contractor_menu (contractor_menu);
populate_contractor_menu (contractor_submenu);
return item_context_menu;
}

Expand Down
26 changes: 18 additions & 8 deletions src/Views/Page.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class Page : Gtk.ScrolledWindow {
protected Gtk.ActionBar? toolbar = null;
protected Gtk.Button? show_sidebar_button = null;

private ViewCollection view = null;
private ViewCollection view;
private Gtk.Window container = null;
private Gdk.Rectangle last_position = Gdk.Rectangle ();
private Gtk.Widget event_source = null;
Expand All @@ -45,7 +45,7 @@ public abstract class Page : Gtk.ScrolledWindow {
private OneShotScheduler? update_actions_scheduler = null;
private Gtk.ActionGroup? action_group = null;
private Gtk.ActionGroup[]? common_action_groups = null;
private GLib.List<Gtk.Widget>? contractor_menu_items = null;
private GLib.List<Gtk.Widget> contractor_menu_items;
protected Gtk.Box header_box;
protected GLib.Settings ui_settings;

Expand Down Expand Up @@ -90,6 +90,7 @@ public abstract class Page : Gtk.ScrolledWindow {
// Get global (common) action groups from the application window
common_action_groups = AppWindow.get_instance ().get_common_action_groups ();

contractor_menu_items = new GLib.List<Gtk.Widget> ();
realize.connect (attach_view_signals);
}

Expand All @@ -104,26 +105,35 @@ public abstract class Page : Gtk.ScrolledWindow {
Gee.List<Granite.Services.Contract> contracts = null;
try {
var selected = get_view ().get_selected_sources ();
foreach (var item in selected)
files += (((Photo)item).get_file ());
foreach (var item in selected) {
if (item is MediaSource) {
files += ((MediaSource)item).get_file ();
}
}

contracts = Granite.Services.ContractorProxy.get_contracts_for_files (files);
} catch (Error e) {
warning (e.message);
}
// Remove old contracts
contractor_menu_items.foreach ((item) => {
if (item != null && item is ContractMenuItem) item.destroy ();
// Contractor items only added here below so cannot be null
item.destroy ();
});

//and replace it with menu_item from contractor
for (int i = 0; i < contracts.size; i++) {
var contract = contracts.get (i);
Gtk.MenuItem menu_item;

menu_item = new ContractMenuItem (contract, get_view ().get_selected_sources ());
menu.append (menu_item);
contractor_menu_items.append (menu_item);
var sources = view.get_selected_sources (); // Maybe empty list?
if (sources.size > 0) {
menu_item = new ContractMenuItem (contract, sources);
menu.append (menu_item);
contractor_menu_items.append (menu_item);
}
}

menu.show_all ();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Views/PhotosPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class Library.PhotosPage : CollectionPage {
}

public override bool include_in_view (DataSource source) {
Photo photo = (Photo) source;
return source is Photo && photo != null && photo.get_master_file_format () != PhotoFileFormat.RAW;
Photo? photo = (source is Photo) ? (Photo)source : null;
return photo != null && photo.get_master_file_format () != PhotoFileFormat.RAW;
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/Widgets/ContractMenuItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ public class ContractMenuItem : Gtk.MenuItem {
try {
File[] modified_files = null;
foreach (var source in sources) {
Photo modified_file = (Photo)source;
if (modified_file.get_file_format () == PhotoFileFormat.RAW || !modified_file.has_alterations ())
modified_files += modified_file.get_file ();
else
modified_files += modified_file.get_modified_file ();
assert (source is Photo);
var photo_source = (Photo)source;
if (photo_source.get_file_format () == PhotoFileFormat.RAW ||
!photo_source.has_alterations ()) {

modified_files += photo_source.get_file ();
} else {
modified_files += photo_source.get_modified_file ();
}
}

contract.execute_with_files (modified_files);
} catch (Error err) {
warning (err.message);
Expand Down
Loading