gio: Improve the Run method API in GLib.Application

We don't need an argc parameter, but the program name is required.

Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
This commit is contained in:
Antonius Riha 2014-09-17 06:33:32 +02:00 committed by Bertrand Lorentz
parent 3680a39323
commit b06ff4fd15
5 changed files with 101 additions and 0 deletions

67
gio/Application.cs Normal file
View File

@ -0,0 +1,67 @@
//
// Application.cs
//
// Author(s):
// Antonius Riha <antoniusriha@gmail.com>
//
// Copyright (c) 2014 Antonius Riha
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
using System;
using System.Runtime.InteropServices;
namespace GLib
{
public partial class Application
{
public Application () : this (null, ApplicationFlags.None)
{
}
[DllImport (GioGlobal.GioNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern int g_application_run (IntPtr raw, int argc, IntPtr argv);
public int Run ()
{
return Run (null, null);
}
public int Run (string program_name, string[] args)
{
var argc = 0;
var argv = IntPtr.Zero;
if (program_name != null) {
program_name = program_name.Trim ();
if (program_name.Length == 0) {
throw new ArgumentException ("program_name must not be empty.", "program_name");
}
if (args == null) {
throw new ArgumentNullException ("args");
}
var prog_args = new string [args.Length + 1];
prog_args [0] = program_name;
args.CopyTo (prog_args, 1);
argc = prog_args.Length;
argv = new Argv (prog_args).Handle;
}
return g_application_run (Handle, argc, argv);
}
}
}

View File

@ -106,6 +106,7 @@
<attr path="/api/namespace/object/property[@type='GDbusServerFlags']" name="type">GDBusServerFlags</attr>
<attr path="/api/namespace/object/property[@type='GIoStream']" name="type">GIOStream</attr>
<attr path="/api/namespace/object/property[@type='GUnixFdList']" name="type">GUnixFDList</attr>
<attr path="/api/namespace/object[@cname='GApplication']/method[@cname='g_application_run']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GApplication']/signal[@cname='activate']" name="name">Activated</attr>
<attr path="/api/namespace/object[@cname='GApplication']/signal[@cname='open']" name="name">Opened</attr>
<attr path="/api/namespace/object[@cname='GDBusAuthObserver']/signal[@cname='authorize-authenticated-peer']" name="name">AuthenticatedPeerAuthorized</attr>

29
gio/GioGlobal.cs Normal file
View File

@ -0,0 +1,29 @@
//
// Global.cs
//
// Author(s):
// Antonius Riha <antoniusriha@gmail.com>
//
// Copyright (c) 2014 Antonius Riha
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GLib
{
public partial class GioGlobal
{
internal const string GioNativeDll = "libgio-2.0-0.dll";
}
}

View File

@ -12,10 +12,12 @@ glue_includes = gio/gio.h
POLICY_VERSIONS=
sources = \
Application.cs \
AppInfoAdapter.cs \
FileAdapter.cs \
FileEnumerator.cs \
FileFactory.cs \
GioGlobal.cs \
GioStream.cs \
IFile.cs

View File

@ -368,6 +368,8 @@
<Compile Include="generated\GLib\ZlibCompressor.cs" />
<Compile Include="generated\GLib\ZlibCompressorFormat.cs" />
<Compile Include="generated\GLib\ZlibDecompressor.cs" />
<Compile Include="Application.cs" />
<Compile Include="GioGlobal.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\glib\glib.csproj">