Skip to content

Commit

Permalink
code improvements; style switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
artemanufrij committed Oct 31, 2018
1 parent 4d5c017 commit 6740186
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 146 deletions.
8 changes: 8 additions & 0 deletions data/com.github.artemanufrij.playmyvideos.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
</screenshot>
</screenshots>
<releases>
<release version="1.1.2" date="2018-11-04">
<description>
<p>New:</p>
<ul>
<li>Style switcher</li>
</ul>
</description>
</release>
<release version="1.1.1" date="2018-10-24">
<description>
<p>Fixed:</p>
Expand Down
23 changes: 6 additions & 17 deletions src/Dialogs/Preferences.vala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2017-2017 Artem Anufrij <[email protected]>
* Copyright (c) 2017-2018 Artem Anufrij <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -27,7 +27,7 @@

namespace PlayMyVideos.Dialogs {
public class Preferences : Gtk.Dialog {
PlayMyVideos.Settings settings;
Settings settings;

construct {
settings = PlayMyVideos.Settings.get_default ();
Expand Down Expand Up @@ -58,14 +58,6 @@ namespace PlayMyVideos.Dialogs {
grid.row_spacing = 12;
grid.margin = 12;

var use_dark_theme_label = new Gtk.Label (_("Use Dark Theme"));
use_dark_theme_label.halign = Gtk.Align.START;
var use_dark_theme = new Gtk.Switch ();
use_dark_theme.active = settings.use_dark_theme;
use_dark_theme.notify["active"].connect (() => {
settings.use_dark_theme = use_dark_theme.active;
});

var load_content_label = new Gtk.Label (_("Load Content from The Movie DB"));
load_content_label.halign = Gtk.Align.START;
var load_content = new Gtk.Switch ();
Expand All @@ -82,13 +74,10 @@ namespace PlayMyVideos.Dialogs {
settings.save_custom_covers = save_custom_covers.active;
});

grid.attach (use_dark_theme_label, 0, 0);
grid.attach (use_dark_theme, 1, 0);
grid.attach (new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 1, 2, 1);
grid.attach (load_content_label, 0, 2);
grid.attach (load_content, 1, 2);
grid.attach (save_custom_covers_label, 0, 3);
grid.attach (save_custom_covers, 1, 3);
grid.attach (load_content_label, 0, 0);
grid.attach (load_content, 1, 0);
grid.attach (save_custom_covers_label, 0, 1);
grid.attach (save_custom_covers, 1, 1);

content.pack_start (grid, false, false, 0);

Expand Down
274 changes: 145 additions & 129 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,60 +121,55 @@ namespace PlayMyVideos {
load_settings ();
build_ui ();

load_content_from_database.begin (
(obj, res) => {
library_manager.sync_library_content.begin ();
visible_playing_button ();
});
this.motion_notify_event.connect (
(event) => {
show_mouse_cursor ();
return false;
});
this.window_state_event.connect (
(event) => {
current_state = event.new_window_state;
return false;
});
this.delete_event.connect (
() => {
save_settings ();
player_view.reset ();
return false;
});
this.key_press_event.connect (
(key) => {
if (content.visible_child_name == "player") {
switch (key.keyval) {
case Gdk.Key.Left :
if (Gdk.ModifierType.MOD1_MASK in key.state) {
break;
}
if (Gdk.ModifierType.SHIFT_MASK in key.state) {
seek_seconds (-300);
} else {
seek_seconds (-10);
}
return true;
case Gdk.Key.Right :
if (Gdk.ModifierType.MOD1_MASK in key.state) {
break;
}
if (Gdk.ModifierType.SHIFT_MASK in key.state) {
seek_seconds (300);
} else {
seek_seconds (10);
}
return true;
case Gdk.Key.space :
toggle_playing ();
return true;
load_content_from_database.begin ((obj, res) => {
library_manager.sync_library_content.begin ();
visible_playing_button ();
});
this.motion_notify_event.connect ((event) => {
show_mouse_cursor ();
return false;
});
this.window_state_event.connect ((event) => {
current_state = event.new_window_state;
return false;
});
this.delete_event.connect (() => {
save_settings ();
player_view.reset ();
return false;
});
this.key_press_event.connect ((key) => {
if (content.visible_child_name == "player") {
switch (key.keyval) {
case Gdk.Key.Left :
if (Gdk.ModifierType.MOD1_MASK in key.state) {
break;
}
if (Gdk.ModifierType.SHIFT_MASK in key.state) {
seek_seconds (-300);
} else {
seek_seconds (-10);
}
} else if (!search_entry.is_focus && key.str.strip ().length > 0) {
search_entry.grab_focus ();
return true;
case Gdk.Key.Right :
if (Gdk.ModifierType.MOD1_MASK in key.state) {
break;
}
if (Gdk.ModifierType.SHIFT_MASK in key.state) {
seek_seconds (300);
} else {
seek_seconds (10);
}
return true;
case Gdk.Key.space :
toggle_playing ();
return true;
}
return false;
});
} else if (!search_entry.is_focus && key.str.strip ().length > 0) {
search_entry.grab_focus ();
}
return false;
});
}

private void build_ui () {
Expand All @@ -183,93 +178,21 @@ namespace PlayMyVideos {

headerbar = new Gtk.HeaderBar ();
headerbar.show_close_button = true;
headerbar.get_style_context ().add_class ("default-decoration");
headerbar.title = _ ("Cinema");

play_button = new Gtk.Button.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
play_button.valign = Gtk.Align.CENTER;
play_button.tooltip_text = _ ("Resume playing");
play_button.clicked.connect (
() => {
toggle_playing ();
});

headerbar.pack_start (play_button);
header_build_play_button ();

//SETTINGS MENU
app_menu = new Gtk.MenuButton ();
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR));
header_build_app_menu ();

var settings_menu = new Gtk.Menu ();
header_build_style_switcher ();

var menu_item_library = new Gtk.MenuItem.with_label (_ ("Change Video Folder…"));
menu_item_library.activate.connect (
() => {
var folder = library_manager.choose_folder ();
if (folder != null) {
settings.library_location = folder;
library_manager.scan_local_library_for_new_files (folder);
}
});

var menu_item_import = new Gtk.MenuItem.with_label (_ ("Import Videos…"));
menu_item_import.activate.connect (
() => {
var folder = library_manager.choose_folder ();
if (folder != null) {
library_manager.scan_local_library_for_new_files (folder);
}
});

menu_item_rescan = new Gtk.MenuItem.with_label (_ ("Rescan Library"));
menu_item_rescan.activate.connect (
() => {
reset_all_views ();
library_manager.rescan_library ();
});

var menu_item_preferences = new Gtk.MenuItem.with_label (_ ("Preferences"));
menu_item_preferences.activate.connect (
() => {
var preferences = new Dialogs.Preferences (this);
preferences.run ();
});

settings_menu.append (menu_item_library);
settings_menu.append (menu_item_import);
settings_menu.append (new Gtk.SeparatorMenuItem ());
settings_menu.append (menu_item_rescan);
settings_menu.append (new Gtk.SeparatorMenuItem ());
settings_menu.append (menu_item_preferences);
settings_menu.show_all ();

app_menu.popup = settings_menu;
headerbar.pack_end (app_menu);

search_entry = new Gtk.SearchEntry ();
search_entry.placeholder_text = _ ("Search Videos");
search_entry.valign = Gtk.Align.CENTER;
search_entry.search_changed.connect (() => {
boxes_view.filter = search_entry.text;
});
headerbar.pack_end (search_entry);
header_build_search_entry ();

// SPINNER
spinner = new Gtk.Spinner ();
headerbar.pack_end (spinner);

navigation_button = new Gtk.Button ();
navigation_button.label = _ ("Back");
navigation_button.valign = Gtk.Align.CENTER;
navigation_button.can_focus = false;
navigation_button.get_style_context ().add_class ("back-button");
navigation_button.clicked.connect (() => {
settings.last_played_video_progress = player_view.playback.progress;
show_boxes ();
player_view.clear_last_size ();
});

headerbar.pack_start (navigation_button);
header_build_back_button ();

this.set_titlebar (headerbar);

Expand Down Expand Up @@ -319,6 +242,99 @@ namespace PlayMyVideos {
navigation_button.hide ();
}

private void header_build_play_button () {
play_button = new Gtk.Button.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
play_button.valign = Gtk.Align.CENTER;
play_button.tooltip_text = _ ("Resume playing");
play_button.clicked.connect (() => {
toggle_playing ();
});

headerbar.pack_start (play_button);
}

private void header_build_back_button () {
navigation_button = new Gtk.Button ();
navigation_button.label = _ ("Back");
navigation_button.valign = Gtk.Align.CENTER;
navigation_button.can_focus = false;
navigation_button.get_style_context ().add_class ("back-button");
navigation_button.clicked.connect (() => {
settings.last_played_video_progress = player_view.playback.progress;
show_boxes ();
player_view.clear_last_size ();
});

headerbar.pack_start (navigation_button);
}

private void header_build_app_menu () {
app_menu = new Gtk.MenuButton ();
app_menu.set_image (new Gtk.Image.from_icon_name ("open-menu-symbolic", Gtk.IconSize.LARGE_TOOLBAR));

var settings_menu = new Gtk.Menu ();

var menu_item_library = new Gtk.MenuItem.with_label (_ ("Change Video Folder…"));
menu_item_library.activate.connect (() => {
var folder = library_manager.choose_folder ();
if (folder != null) {
settings.library_location = folder;
library_manager.scan_local_library_for_new_files (folder);
}
});

var menu_item_import = new Gtk.MenuItem.with_label (_ ("Import Videos…"));
menu_item_import.activate.connect (() => {
var folder = library_manager.choose_folder ();
if (folder != null) {
library_manager.scan_local_library_for_new_files (folder);
}
});

menu_item_rescan = new Gtk.MenuItem.with_label (_ ("Rescan Library"));
menu_item_rescan.activate.connect (() => {
reset_all_views ();
library_manager.rescan_library ();
});

var menu_item_preferences = new Gtk.MenuItem.with_label (_ ("Preferences"));
menu_item_preferences.activate.connect (() => {
var preferences = new Dialogs.Preferences (this);
preferences.run ();
});

settings_menu.append (menu_item_library);
settings_menu.append (menu_item_import);
settings_menu.append (new Gtk.SeparatorMenuItem ());
settings_menu.append (menu_item_rescan);
settings_menu.append (new Gtk.SeparatorMenuItem ());
settings_menu.append (menu_item_preferences);
settings_menu.show_all ();

app_menu.popup = settings_menu;
headerbar.pack_end (app_menu);
}

private void header_build_style_switcher () {
var mode_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic");
mode_switch.valign = Gtk.Align.CENTER;
mode_switch.active = settings.use_dark_theme;
mode_switch.notify["active"].connect (() => {
settings.use_dark_theme = mode_switch.active;
});
headerbar.pack_end (mode_switch);
}

private void header_build_search_entry () {
search_entry = new Gtk.SearchEntry ();
search_entry.placeholder_text = _ ("Search Videos");
search_entry.valign = Gtk.Align.CENTER;
search_entry.search_changed.connect (() => {
boxes_view.filter = search_entry.text;
});
headerbar.pack_end (search_entry);
}

private void visible_playing_button () {
if (settings.last_played_video_uri != "" && content.visible_child_name != "player") {
var f = File.new_for_uri (settings.last_played_video_uri);
Expand Down

0 comments on commit 6740186

Please sign in to comment.