[gnome-subtitles: 1/2] Fix #134 Set ApplicationID to use .desktop file
- From: Pedro Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles: 1/2] Fix #134 Set ApplicationID to use .desktop file
- Date: Sat, 8 Jun 2019 09:26:06 +0000 (UTC)
commit 7924058a168bdd45017eda7fa400fa15078aedab
Author: Pedro Castro <pedro gnomesubtitles org>
Date: Sat Jun 8 10:23:06 2019 +0100
Fix #134 Set ApplicationID to use .desktop file
Changed the way we use Gtk.Application so we can set the application id.
The application icon is no longer embedded as a resource, instead
IconName is set so the application uses the installed icon.
gnome-subtitles.csproj | 10 +--
src/Glade/MainWindow.ui | 1 -
src/GnomeSubtitles/Core/Base.cs | 36 ++++------
src/GnomeSubtitles/Core/EventHandlers.cs | 6 +-
src/GnomeSubtitles/Execution/Executable.cs | 7 +-
src/GnomeSubtitles/Execution/ExecutionContext.cs | 84 +++++++-----------------
src/GnomeSubtitles/Ui/MainUi.cs | 39 ++++++-----
src/Makefile.am | 1 -
8 files changed, 72 insertions(+), 112 deletions(-)
---
diff --git a/gnome-subtitles.csproj b/gnome-subtitles.csproj
index dea2a47..841e05a 100644
--- a/gnome-subtitles.csproj
+++ b/gnome-subtitles.csproj
@@ -56,10 +56,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
- <EmbeddedResource Include="data\gnome-subtitles.svg">
- <DeployService-Deploy>True</DeployService-Deploy>
- <LogicalName>gnome-subtitles.svg</LogicalName>
- </EmbeddedResource>
<EmbeddedResource Include="src\Glade\MainWindow.ui">
<LogicalName>MainWindow.ui</LogicalName>
</EmbeddedResource>
@@ -287,4 +283,10 @@
<Folder Include="src\SubLib\Util\" />
<Folder Include="src\External\GtkSpell\" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="data\gnome-subtitles.svg">
+ <DeployService-Deploy>True</DeployService-Deploy>
+ <LogicalName>gnome-subtitles.svg</LogicalName>
+ </None>
+ </ItemGroup>
</Project>
\ No newline at end of file
diff --git a/src/Glade/MainWindow.ui b/src/Glade/MainWindow.ui
index e4ca82e..e815e61 100644
--- a/src/Glade/MainWindow.ui
+++ b/src/Glade/MainWindow.ui
@@ -25,7 +25,6 @@
</object>
<object class="GtkApplicationWindow" id="window">
<property name="can_focus">False</property>
- <property name="title">Gnome Subtitles</property>
<signal name="delete-event" handler="OnWindowDelete" swapped="no"/>
<signal name="size-allocate" handler="OnSizeAllocated" swapped="no"/>
<child>
diff --git a/src/GnomeSubtitles/Core/Base.cs b/src/GnomeSubtitles/Core/Base.cs
index 8c66d5b..1ef8bd1 100644
--- a/src/GnomeSubtitles/Core/Base.cs
+++ b/src/GnomeSubtitles/Core/Base.cs
@@ -35,7 +35,7 @@ public delegate void VideoLoadedHandler (Uri videoUri);
public delegate void TimingModeChangedHandler (TimingMode timingMode);
public delegate void BasicEventHandler ();
-public class Base {
+public static class Base {
private static MainUi ui = null;
private static ExecutionContext executionContext = null;
private static EventHandlers handlers = null;
@@ -147,25 +147,20 @@ public class Base {
/* Public methods */
/// <summary>Runs the main GUI, after initialization.</summary>
- public static void Run (ExecutionContext executionContext) {
- Init(executionContext);
-
- ui.Start();
- executionContext.RunApplication();
+ public static void Execute (ExecutionContext context) {
+ executionContext = context;
+
+ executionContext.Execute(() => {
+ Init();
+ ui.Start();
+ });
}
/// <summary>Quits the program.</summary>
- public static void Quit () {
- ui.Video.Quit();
- executionContext.QuitApplication();
+ public static bool Quit () {
+ return ui.Quit();
}
- //public static void Kill () {
- // clipboards.WatchPrimaryChanges = false;
- // ui.Kill();
- // executionContext.QuitApplication();
- //}
-
public static void NewDocument () {
if (IsDocumentLoaded)
CloseDocument();
@@ -266,17 +261,8 @@ public class Base {
/* Private members */
/// <summary>Initializes the base program structure.</summary>
- /// <remarks>Nothing is done if initialization has already occurred. The core value is checked for
this,
- /// if it's null then initialization hasn't occurred yet.</remarks>
- private static void Init (ExecutionContext newExecutionContext) {
- if ((executionContext != null) && (executionContext.Initialized))
- throw new Exception("The Base environment was already initialized.");
-
- executionContext = newExecutionContext;
- executionContext.InitApplication();
-
+ private static void Init () {
Catalog.Init(ExecutionContext.TranslationDomain, ExecutionContext.LocaleDir);
-
/* Initialize Command manager */
commandManager = new CommandManager();
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 2fd0ef3..8b25269 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -100,7 +100,7 @@ public class EventHandlers {
}
public void OnFileQuit (object o, EventArgs args) {
- Base.Ui.Quit();
+ Base.Quit();
}
@@ -456,8 +456,8 @@ public class EventHandlers {
/* Window */
public void OnWindowDelete (object o, DeleteEventArgs args) {
- Base.Ui.Quit();
- args.RetVal = true;
+ bool quit = Base.Quit();
+ args.RetVal = !quit; //True to keep the window open
}
public void OnSizeAllocated (object o, SizeAllocatedArgs args) {
diff --git a/src/GnomeSubtitles/Execution/Executable.cs b/src/GnomeSubtitles/Execution/Executable.cs
index 0d805ac..9e0da46 100644
--- a/src/GnomeSubtitles/Execution/Executable.cs
+++ b/src/GnomeSubtitles/Execution/Executable.cs
@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-using GnomeSubtitles.Core;
+using GnomeSubtitles.Core;
using SubLib.Util;
using System;
using System.Runtime.InteropServices;
@@ -70,7 +70,7 @@ public class Executable {
ExecutionContext executionContext = new ExecutionContext(args);
/* If on unix, set process name to gnome-subtitles instead of mono default */
- if (executionContext.PlatformIsUnix) {
+ if (Environment.OSVersion.Platform == PlatformID.Unix) {
SetProcessName(executionContext.ExecutableName);
}
@@ -97,9 +97,10 @@ public class Executable {
Console.Error.WriteLine(domain + " | " + level + " | " + message);
});
- Base.Run(executionContext);
+ Base.Execute(executionContext);
}
+
/* Private members */
///// <summary>Kills the window in the most quick and unfriendly way.</summary>
diff --git a/src/GnomeSubtitles/Execution/ExecutionContext.cs
b/src/GnomeSubtitles/Execution/ExecutionContext.cs
index e0c268e..3831657 100644
--- a/src/GnomeSubtitles/Execution/ExecutionContext.cs
+++ b/src/GnomeSubtitles/Execution/ExecutionContext.cs
@@ -17,57 +17,31 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-using Gtk;
using System;
using System.Reflection;
namespace GnomeSubtitles.Execution {
public class ExecutionContext {
- private bool initialized = false;
- private bool running = false;
+ private Gtk.Application app = null;
/* Constant strings */
private const string applicationName = "Gnome Subtitles";
- private const string applicationID = "gnome-subtitles";
+ private const string applicationID = "org.gnome.GnomeSubtitles";
+ private const string iconName = "gnome-subtitles";
+ private const string executableName = "gnome-subtitles";
/* Dynamic variables */
private string localeDir = String.Empty;
- private bool platformIsWindows = false;
- private bool platformIsUnix = false;
-
private string[] args = null;
public ExecutionContext (string[] args) {
this.args = args;
-
- SetDynamicVariables();
- }
-
- private void SetDynamicVariables () {
- this.localeDir = System.AppDomain.CurrentDomain.BaseDirectory + "../../share/locale";
- //this.localeDir = "/usr/share/locale"; //for testing
-
- /* Handle platform */
- switch (Environment.OSVersion.Platform) {
- case PlatformID.Win32NT:
- case PlatformID.Win32S:
- case PlatformID.Win32Windows:
- case PlatformID.WinCE:
- platformIsWindows = true;
- break;
- case PlatformID.Unix:
- platformIsUnix = true;
- break;
- }
}
+
/* Public properties */
- public bool Initialized {
- get { return initialized; }
- }
-
public string ApplicationName {
get { return applicationName; }
}
@@ -75,14 +49,18 @@ public class ExecutionContext {
public string ApplicationID {
get { return applicationID; }
}
+
+ public string IconName {
+ get { return iconName; }
+ }
public string ExecutableName {
- get { return applicationID; }
+ get { return executableName; }
}
//Unix only
public string LocaleDir {
- get { return localeDir; }
+ get { return AppDomain.CurrentDomain.BaseDirectory + "../../share/locale"; }
}
public string Version {
@@ -101,38 +79,26 @@ public class ExecutionContext {
public string TranslationDomain {
get { return applicationID; }
}
-
- public bool PlatformIsWindows {
- get { return platformIsWindows; }
- }
-
- public bool PlatformIsUnix {
- get { return platformIsUnix; }
+
+ public Gtk.Application Application {
+ get { return app; }
}
/* Public methods */
- public void InitApplication () {
- if (!initialized) {
- initialized = true;
- Application.Init();
- }
- }
+ public void Execute (Action methodToExecute) {
+ GLib.Global.ApplicationName = applicationName;
+
+ app = new Gtk.Application(applicationID, GLib.ApplicationFlags.None);
- public void RunApplication () {
- if (initialized && (!running)) {
- running = true;
- Application.Run();
- }
+ app.Activated += (sender, e) => {
+ methodToExecute();
+ };
+
+ app.Run(0, "");
}
-
- public void QuitApplication () {
- initialized = false;
- running = false;
- Application.Quit();
- }
-
+
/* Private methods */
@@ -148,4 +114,4 @@ public class ExecutionContext {
}
-}
+}
\ No newline at end of file
diff --git a/src/GnomeSubtitles/Ui/MainUi.cs b/src/GnomeSubtitles/Ui/MainUi.cs
index 1801eab..0034f15 100644
--- a/src/GnomeSubtitles/Ui/MainUi.cs
+++ b/src/GnomeSubtitles/Ui/MainUi.cs
@@ -20,6 +20,7 @@
using GnomeSubtitles.Core;
using GnomeSubtitles.Dialog;
using GnomeSubtitles.Dialog.Message;
+using GnomeSubtitles.Execution;
using GnomeSubtitles.Ui.Edit;
using GnomeSubtitles.Ui.VideoPreview;
using GnomeSubtitles.Ui.View;
@@ -46,14 +47,22 @@ public class MainUi {
/* Constant strings */
private const string uiResourceName = "MainWindow.ui";
- private const string iconResourceName = "gnome-subtitles.svg";
public MainUi (EventHandlers handlers) {
builder = ReadUIContent(uiResourceName, Base.ExecutionContext.TranslationDomain);
window = builder.GetObject("window") as Window;
- window.Icon = new Gdk.Pixbuf(null, iconResourceName);
+
+ /* Setting the iconName and wmClass (app name) name is not necessary if a standard desktop
environment is
+ * executing the application, in which case this information is obtained from the .desktop
file. This is
+ * here just in case a non-standard environment is in place.
+ */
+ window.IconName = Base.ExecutionContext.IconName;
+ window.SetWmclass(Base.ExecutionContext.ApplicationName,
Base.ExecutionContext.ApplicationName);
+
window.SetDefaultSize(Base.Config.ViewWindowWidth, Base.Config.ViewWindowHeight);
+
+ Base.ExecutionContext.Application.AddWindow(window);
video = new Video();
view = new SubtitleView();
@@ -119,24 +128,22 @@ public class MainUi {
}
/// <summary>Quits the application.</summary>
- public void Quit () {
- if (ToCloseAfterWarning())
- Base.Quit();
+ public bool Quit () {
+ if (ToCloseAfterWarning()) {
+ Video.Quit();
+ window.Destroy();
+ }
+
+ return false;
}
- ///// <summary>Kills the window in the most quick and unfriendly way.</summary>
- // public void Kill () {
- //window.Destroy();
- //}
-
- /// <summary>Creates a new subtitles document for the specified path.</summary>
- /// <param name="path">The subtitles' filename. If it's an empty string, 'Unsaved Subtitles' will be
used instead.</param>
- /// <remarks>If there's a document open with unsaved changes, a warning dialog is shown.</remarks>
+ /// <summary>Creates a new subtitles document for the specified path.</summary>
+ /// <param name="path">The subtitles' filename. If it's an empty string, 'Unsaved Subtitles' will be
used instead.</param>
+ /// <remarks>If there's a document open with unsaved changes, a warning dialog is shown.</remarks>
public void New () {
- if (!ToCreateNewAfterWarning())
- return;
- else
+ if (ToCreateNewAfterWarning()) {
Base.NewDocument();
+ }
}
/// <summary>Shows the open dialog and possibly opens a subtitle.</summary>
diff --git a/src/Makefile.am b/src/Makefile.am
index 1b4d10f..5113ca9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,7 +46,6 @@ GSSOURCES = \
GS_RESOURCES = \
$(srcdir)/Glade/MainWindow.ui \
- $(GS_DATADIR)/gnome-subtitles.svg \
$(GS_DATADIR)/gnome-subtitles-logo.png
GS_SYSTEM_REFERENCES = \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]