Commit 7924058a authored by Pedro Castro's avatar Pedro Castro

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.
parent 5d6c9bbc
......@@ -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
......@@ -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>
......
......@@ -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();
......
......@@ -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) {
......
......@@ -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>
......
......@@ -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
......@@ -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>
......
......@@ -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 = \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment