"Fossies" - the Fresh Open Source Software Archive

Member "seahorse-3.34/common/util.vala" (1 Oct 2019, 2451 Bytes) of package /linux/privat/seahorse-3.34.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Vala source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Seahorse
    3  *
    4  * Copyright (C) 2003 Jacob Perkins
    5  * Copyright (C) 2004-2005 Stefan Walter
    6  * Copyright (C) 2011 Collabora Ltd.
    7  *
    8  * This program is free software; you can redistribute it and/or modify
    9  * it under the terms of the GNU General Public License as published by
   10  * the Free Software Foundation; either version 2 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This program is distributed in the hope that it will be useful,
   14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   16  * See the GNU General Public License for more details.
   17  * You should have received a copy of the GNU General Public License
   18  * along with this program; if not, see <http://www.gnu.org/licenses/>.
   19  */
   20 
   21 namespace Seahorse {
   22 
   23 namespace Util {
   24 
   25     public void show_error (Gtk.Widget? parent,
   26                             string? heading,
   27                             string? message) {
   28         Gtk.Window? window = null;
   29 
   30         if (message == null)
   31             message = "";
   32 
   33         if (parent != null) {
   34             if (!(parent is Gtk.Window))
   35                 parent = parent.get_toplevel();
   36             if (parent is Gtk.Window)
   37                 window = (Gtk.Window)parent;
   38         }
   39 
   40         var dialog = new Gtk.MessageDialog(window, Gtk.DialogFlags.MODAL,
   41                                            Gtk.MessageType.ERROR,
   42                                            Gtk.ButtonsType.CLOSE, "");
   43         if (heading == null)
   44             dialog.set("text", message);
   45         else
   46             dialog.set("text", heading, "secondary-text", message);
   47 
   48         dialog.run();
   49         dialog.destroy();
   50     }
   51 
   52     public string get_display_date_string (uint64 time)
   53     {
   54         if (time == 0)
   55             return "";
   56         var created_date = new DateTime.from_unix_utc((int64) time);
   57         return created_date.format("%x");
   58     }
   59 
   60     public Gtk.Builder load_built_contents(Gtk.Container? frame,
   61                                            string name) {
   62         var builder = new Gtk.Builder();
   63         string path = "/org/gnome/Seahorse/seahorse-%s.ui".printf(name);
   64 
   65         if (frame != null && frame is Gtk.Dialog)
   66             frame = ((Gtk.Dialog)frame).get_content_area();
   67 
   68         try {
   69             builder.add_from_resource(path);
   70             var obj = builder.get_object(name);
   71             if (obj == null) {
   72                 GLib.critical("Couldn't find object named %s in %s", name, path);
   73             } else if (frame != null) {
   74                 var widget = (Gtk.Widget)obj;
   75                 frame.add(widget);
   76                 widget.show();
   77             }
   78         } catch (GLib.Error err) {
   79             GLib.critical("Couldn't load %s: %s", path, err.message);
   80         }
   81 
   82         return builder;
   83     }
   84 }
   85 
   86 }