alr2appimage_0.9.3_fba60fa7/src/desktop_file.adb

  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
with Ada.Strings.Equal_Case_Insensitive;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling;

package body Desktop_File is

   use type String_Vectors.Vector; -- make "&" visible

   Categories : constant String_Vectors.Vector := String_Vectors.Empty_Vector &
      ("AudioVideo") &
      -- A multimedia (audio/video) application

      ("Audio") &
      -- An audio application
      -- Desktop entry must include AudioVideo as well

      ("Video") &
      -- A video application
      -- Desktop entry must include AudioVideo as well

      ("Development") &
      -- An application for development

      ("Education") &
      -- Educational software

      ("Game") &
      -- A game

      ("Graphics") &
      -- Graphical application

      ("Network") &
      -- Network application such as a web browser

      ("Office") &
      -- An office type application

      ("Settings") &
      -- Settings applications
      -- Entries may appear in a separate menu or as part of a "Control Center"

      ("System") &
      -- System (application) & "System Tools" such as say a log viewer or network monitor

      ("Utility")
     -- Small utility application, "Accessories"
     ;

   procedure Put_Value
     (File : File_Type;
      Key, Value : String) is
   begin
      Put_Line (File, Key & "=" & Value);
   end Put_Value;

   procedure Put_Value
     (File : File_Type;
      Key : String;
      Value : Boolean) is
   begin
      Put_Line (File, Key & "=" &
                  Ada.Characters.Handling.To_Lower (Value'Image));
   end Put_Value;

   procedure Write
     (Name : String;
      Comment : String;
      Exec : String;
      Icon : String;
      Terminal : Boolean;
      Tags : String_Vectors.Vector) is

      Desktop_File : File_Type;
   begin
      Create (File => Desktop_File, Name => Exec & ".desktop");

      Put_Line (Desktop_File, "[Desktop Entry]");

      Put_Value (Desktop_File, "Name", Name);
      Put_Value (Desktop_File, "Comment", Comment);
      Put_Value (Desktop_File, "Exec", Exec);
      Put_Value (Desktop_File, "Icon", Icon);
      Put_Value (Desktop_File, "Terminal", Terminal);

      Put_Value (Desktop_File, "Type", "Application");

      Put (Desktop_File, "Keywords=");
      for Tag of Tags loop
         Put (Desktop_File, Tag & ";");
      end loop;
      New_Line (Desktop_File);

      Put (Desktop_File, "Categories=");
      for Tag of Tags loop
         for Each_Category of Categories loop
            if Ada.Strings.Equal_Case_Insensitive (Each_Category, Tag)
            then
               Put (Desktop_File, Each_Category & ";");
            end if;
         end loop;
      end loop;
      New_Line (Desktop_File);

      Close (Desktop_File);

   end Write;

end Desktop_File;