Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 154 lines (127 sloc) 5.309 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
// Application.cs
//
// Copyright (c) 2008 Ethan Osten
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Collections;

using System.Runtime.InteropServices;
using System.Text;

using NDesk.DBus;

using Gtk;

using Summa.Core;
using Summa.Data;
using Summa.Gui;

namespace Summa.Core {
    public static class Application {
        public static Gtk.ListStore TagStore;
        public static ArrayList Browsers;
        public static Summa.Gui.StatusIcon StatusIcon;
        public static Updater Updater;
        public static DBusInterface DBus;
        public static bool WindowsShown;
        
        public static void Main() {
            //GLib.Thread.Init();
            Gdk.Threads.Init();
            
            Gtk.Application.Init();
            SetProcessName("summa");
            
            GLib.Log.SetLogHandler(null, GLib.LogLevelFlags.All, new GLib.LogFunc(Log.LogFunc)); //FIXME
            
            /*
* the ListStore for all TagViews, since tags don't
* vary by context.
*/
            TagStore = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string));
            
            Updater = new Updater();
            DBus = new DBusInterface();
            /*
* a list of browser instances - when a browser is created, it
* should be added to this list, and when it is destroyed, it
* should be removed.
*/
            Browsers = new ArrayList();
            Browsers.Add(new Browser());
            StatusIcon = new Summa.Gui.StatusIcon();
            
            foreach ( Browser browser in Browsers ) {
                browser.ShowAll();
            }
            WindowsShown = true;
            
            DebugTest();
            
            Gtk.Application.Run();
        }
        
        private static void DebugTest() {
            /*foreach ( ISource source in Feeds.GetFeeds() ) {
foreach ( Item item in source.Items ) {
item.Read = true;
}
}*/
        }
        
        public static void CloseWindow(Browser browser) {
            if ( Browsers.Count == 1 ) {
                /* get dimensions */
                int width;
                int height;
                
                browser.GetSize(out width, out height);
                
                Config.WindowWidth = width;
                Config.WindowHeight = height;
                
                /* get pane positions */
                int main_size;
                int left_size;
                int right_size;
                
                main_size = browser.main_paned.Position;
                left_size = browser.left_paned.Position;
                right_size = browser.right_paned.Position;
                
                Config.MainPanePosition = main_size;
                Config.LeftPanePosition = left_size;
                Config.RightPanePosition = right_size;
                
                Bus.Session.Unregister(new ObjectPath(DBus.ObjPath));
                Bus.Session.ReleaseName(DBus.BusName);
                
                Gtk.Main.Quit();
            } else {
                browser.Destroy();
                Browsers.Remove(browser);
            }
        }
        
        public static void ToggleShown() {
            if ( WindowsShown ) {
                foreach ( Browser browser in Application.Browsers ) {
                    browser.Hide();
                }
                WindowsShown = false;
            } else {
                foreach ( Browser browser in Application.Browsers ) {
                    browser.Show();
                }
                WindowsShown = true;
            }
        }
        
        /* this stuff from Beagle */
[DllImport("libc")]
private static extern int prctl (int option, byte [] arg2, ulong arg3, ulong arg4, ulong arg5);

/* From /usr/include/linux/prctl.h */
private const int PR_SET_NAME = 15;

public static void SetProcessName(string name) {
if (prctl (PR_SET_NAME, Encoding.ASCII.GetBytes (name + '\0'), 0, 0, 0) < 0) {
Log.Message(String.Format("Couldn't set process name to '{0}': {1}", name, Mono.Unix.Native.Stdlib.GetLastError()));
}
}
    }
}
Something went wrong with that request. Please try again.