Пример #1
0
        public static void StopEmissionByName(GLib.Object o, string signal)
        {
            IntPtr intPtr = Marshaller.StringToPtrGStrdup(signal);

            stopEmmisionByName(o.Handle, intPtr);
            Marshaller.Free(intPtr);
        }
Пример #2
0
        void DataRead(GLib.Object obj, GLib.AsyncResult res)
        {
            File file = FileAdapter.GetObject(obj);

            Regex keyValueRegex = new Regex(
                @"(^(\s)*(?<Key>([^\=^\n]+))[\s^\n]*\=(\s)*(?<Value>([^\n]+(\n){0,1})))",
                RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled |
                RegexOptions.CultureInvariant
                );

            using (DataInputStream stream = new DataInputStream(file.ReadFinish(res))) {
                ulong  len;
                string line;
                while ((line = stream.ReadLine(out len, null)) != null)
                {
                    line = line.Trim();

                    Match match = keyValueRegex.Match(line);
                    if (match.Success)
                    {
                        string key = match.Groups["Key"].Value;
                        string val = match.Groups["Value"].Value;

                        if (key.Equals(NameTag))
                        {
                            Name = val;
                        }
                        else if (key.Equals(DescTag))
                        {
                            Description = val;
                        }
                        else if (key.Equals(AppUriTag))
                        {
                            AppUri = val;
                        }
                        else if (key.Equals(IconTag))
                        {
                            if (val.StartsWith("./") && val.Length > 2)
                            {
                                IconFile = file.Parent.GetChild(val.Substring(2));
                                if (IconFile.Exists)
                                {
                                    Icon = DockServices.Drawing.LoadIcon(IconFile.Path + ";;extension");
                                }
                            }
                            else
                            {
                                Icon = DockServices.Drawing.LoadIcon(val + ";;extension", 128);
                            }
                        }
                    }
                }
            }
            OnDataReady();
        }
Пример #3
0
        public static void StopEmissionByName(GLib.Object o, string signal)
        {
            if (Impl.g_signal_stop_emission_by_name == null)
            {
                return;
            }
            IntPtr intPtr = Marshaller.StringToPtrGStrdup(signal);

            Impl.g_signal_stop_emission_by_name(o.Handle, intPtr);
            Marshaller.Free(intPtr);
        }
Пример #4
0
 static void HandleMountFinished(GLib.Object sender, GLib.AsyncResult result)
 {
     System.Console.WriteLine("handle mount finished");
     if (file.MountEnclosingVolumeFinish(result))
     {
         System.Console.WriteLine("successfull");
     }
     else
     {
         System.Console.WriteLine("Failed");
     }
 }
Пример #5
0
            void InfoLoaded(GLib.Object o, AsyncResult res)
            {
                var items = new List <FilePhoto> ();

                foreach (FileInfo info in file.EnumerateChildrenFinish(res))
                {
                    var i = new Uri(file.GetChild(info.Name).Uri);
                    Log.Debug($"testing uri = {i}");
                    if (App.Instance.Container.Resolve <IImageFileFactory> ().HasLoader(i))
                    {
                        items.Add(new FilePhoto(i));
                    }
                }
                ThreadAssist.ProxyToMain(() => collection.Add(items.ToArray()));
            }
Пример #6
0
            void InfoLoaded(GLib.Object o, GLib.AsyncResult res)
            {
                List <FilePhoto> items = new List <FilePhoto> ();

                foreach (GLib.FileInfo info in file.EnumerateChildrenFinish(res))
                {
                    SafeUri i = new SafeUri(file.GetChild(info.Name).Uri);
                    Hyena.Log.DebugFormat("testing uri = {0}", i);
                    if (ImageFile.HasLoader(i))
                    {
                        items.Add(new FilePhoto(i));
                    }
                }
                ThreadAssist.ProxyToMain(() => collection.Add(items.ToArray()));
            }
Пример #7
0
        public static void Disconnect(GLib.Object o, string name, Delegate handler)
        {
            ObjectSignalKey k = new ObjectSignalKey(o, name);

            if (SignalHandlers[k] != null)
            {
                SignalInfo si         = (SignalInfo)SignalHandlers[k];
                Delegate   newHandler = Delegate.Remove(si.RegisteredHandler, handler);
                if (newHandler == null || handler == null)
                {
                    g_signal_handler_disconnect(o.Handle, si.HandlerId);
                    SignalHandlers.Remove(k);
                }
                else
                {
                    si.RegisteredHandler = newHandler;
                }
            }
        }
Пример #8
0
        public static void Connect(GLib.Object o, string name, bool after, DynamicSignalHandler handler)
        {
            Delegate newHandler;

            Key k = new Key(o, name);

            if (SignalHandlers[k] != null)
            {
                SignalInfo si = (SignalInfo)SignalHandlers[k];
                newHandler           = Delegate.Combine(si.RegisteredHandler, handler);
                si.RegisteredHandler = newHandler;
            }
            else
            {
                IntPtr closure = g_closure_new_simple(_closureSize, IntPtr.Zero);
                g_closure_set_meta_marshal(closure, (IntPtr)GCHandle.Alloc(k), marshalHandler);
                uint signalId = g_signal_connect_closure(o.Handle, name, closure, after);
                SignalHandlers.Add(k, new SignalInfo(signalId, closure, handler));
            }
        }
Пример #9
0
        public static void Connect(GLib.Object o, string name,
                                   bool after, Delegate handler)
        {
            Delegate newHandler;

            ObjectSignalKey k = new ObjectSignalKey(o, name);

            if (!SignalInfo.IsValidDelegate(handler))
            {
                throw new Exception("Invalid delegate");
            }

            if (SignalHandlers [k] != null)
            {
                SignalInfo si = (SignalInfo)SignalHandlers [k];
                if (!si.IsCompatibleDelegate(handler))
                {
                    throw new Exception("Incompatible delegate");
                }

                newHandler = Delegate.Combine(si.RegisteredHandler, handler);
                si.UpdateArgsType(handler);
                si.RegisteredHandler = newHandler;
            }
            else
            {
                if (!SignalInfo.IsValidDelegate(handler))
                {
                    throw new Exception("Invalid delegate");
                }

                // Let's allocate 64bytes for the GClosure, it should be more than necessary.
                IntPtr   closure = g_closure_new_simple(64, IntPtr.Zero);
                GCHandle gch     = GCHandle.Alloc(k);
                g_closure_set_meta_marshal(closure, (IntPtr)gch, marshalHandler);
                uint signalId = g_signal_connect_closure(o.Handle, name, closure, after);
                SignalHandlers.Add(k, new SignalInfo(signalId, closure, handler, gch));
            }
        }
Пример #10
0
        public static object Emit(GLib.Object o, string name, params object[] parameters)
        {
            SignalQuery query;
            IntPtr      type = gstsharp_g_type_from_instance(o.Handle);
            GType       gtype = new GType(type);
            string      signal_name, signal_detail;
            uint        signal_detail_quark = 0;
            int         colon;

            colon = name.LastIndexOf("::");

            if (colon == -1)
            {
                signal_name   = name;
                signal_detail = String.Empty;
            }
            else
            {
                signal_name   = name.Substring(0, colon);
                signal_detail = name.Substring(colon + 2);
            }

            GTypeSignalKey key = new GTypeSignalKey(gtype, signal_name);

            if (SignalEmitInfo[key] == null)
            {
                IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup(signal_name);
                uint   signal_id     = g_signal_lookup(native_string, type);
                GLib.Marshaller.Free(native_string);

                if (signal_id == 0)
                {
                    throw new NotSupportedException(String.Format("{0} has no signal of name {1}", o, name));
                }
                GSignalQuery q = new GSignalQuery();
                g_signal_query(signal_id, ref q);

                if (q.signal_id == 0)
                {
                    throw new NotSupportedException(String.Format("{0} couldn't be queried for signal with name {1}", o, name));
                }

                query = new SignalQuery();

                query.signal_id    = signal_id;
                query.signal_name  = GLib.Marshaller.Utf8PtrToString(q.signal_name);
                query.itype        = new GType(q.itype);
                query.signal_flags = q.signal_flags;
                query.return_type  = new GType(q.return_type);
                query.n_params     = q.n_params;
                query.param_types  = new Type[q.n_params];

                for (int i = 0; i < query.n_params; i++)
                {
                    IntPtr t = Marshal.ReadIntPtr(q.param_types, i);
                    GType  g = new GType(t);

                    query.param_types[i] = (Type)g;
                }

                SignalEmitInfo.Add(key, query);
            }

            query = (SignalQuery)SignalEmitInfo[key];
            GLib.Value[] signal_parameters = new GLib.Value[query.n_params + 1];
            signal_parameters[0] = new GLib.Value(o);

            if (parameters.Length != query.n_params)
            {
                throw new ApplicationException(String.Format("Invalid number of parameters: expected {0}, got {1}", query.n_params, parameters.Length));
            }

            for (int i = 0; i < query.n_params; i++)
            {
                Type expected_type = (Type)query.param_types[i];
                Type given_type    = parameters[i].GetType();

                if (expected_type != given_type && !given_type.IsSubclassOf(given_type))
                {
                    throw new ApplicationException(String.Format("Invalid parameter type: expected {0}, got {1}", expected_type, given_type));
                }

                signal_parameters[i + 1] = new GLib.Value(parameters[i]);
            }

            GLib.Value return_value = new GLib.Value();
            if (query.return_type != GType.Invalid && query.return_type != GType.None)
            {
                return_value.Init(query.return_type);
            }

            if (signal_detail != String.Empty)
            {
                IntPtr native_string = GLib.Marshaller.StringToPtrGStrdup(signal_detail);
                signal_detail_quark = g_quark_from_string(native_string);
                GLib.Marshaller.Free(native_string);
            }

            g_signal_emitv(signal_parameters, query.signal_id, signal_detail_quark, ref return_value);

            foreach (GLib.Value v in signal_parameters)
            {
                v.Dispose();
            }

            object ret = (query.return_type != GType.Invalid && query.return_type != GType.None) ? return_value.Val : null;

            if (ret != null)
            {
                return_value.Dispose();
            }

            return(ret);
        }
Пример #11
0
 public static void Connect(GLib.Object o, string name, Delegate handler)
 {
     Connect(o, name, false, handler);
 }
Пример #12
0
        static void DisconnectNotification(GLib.Object w, string signal, NotifyHandler handler)
        {
            var sig = GLib.Signal.Lookup(w, signal, delegateInstance);

            sig.RemoveDelegate(handler);
        }
Пример #13
0
 public static void Connect(GLib.Object o, string name, DynamicSignalHandler handler)
 {
     Connect(o, name, false, handler);
 }
 public static int RefCount(GLib.Object obj)
 {
     return(gtksharp_object_get_ref_count(obj.Handle));
 }
Пример #15
0
 private void StatusCallback(GLib.Object sender, Tny.Status status)
 {
     this.progressbar.Fraction = status.Fraction;
 }
Пример #16
0
 public static void AddNotification(GLib.Object w, NotifyHandler handler)
 {
     ConnectNotification(w, "notify", handler);
 }
Пример #17
0
 public static void AddNotification(GLib.Object w, string property, NotifyHandler handler)
 {
     ConnectNotification(w, "notify::" + property, handler);
 }
Пример #18
0
 public static void Connect(GLib.Object o, string name, SignalHandler handler)
 {
     Connect(o, name, false, (Delegate)handler);
 }
Пример #19
0
 public static void RemoveNotification(GLib.Object w, NotifyHandler handler)
 {
     DisconnectNotification(w, "notify", handler);
 }
Пример #20
0
 public static void Connect(GLib.Object o, string name,
                            bool after, SignalHandler handler)
 {
     Connect(o, name, after, (Delegate)handler);
 }