~onli/simdock/master

« back to all changes in this revision

Viewing changes to src/main.cc

  • Committer: onli
  • Date: 2016-03-23 03:14:38 UTC
  • Revision ID: git-v1:27c983caf663a5fa655aa04e8d7b2242806e9830
Tags: 1.5
Support svg icons via wxsvg
Internally, wxwidgets and thus simdock still just uses
bitmaps. Support for svg is added by enabling the
launcherDialog to show .svg files, then passing them to
simimage where wxsvg converts them into a bitmap

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
{
75
75
    openOrInitialize (&fullPath, &defaultLaunchers);
76
76
    wxXmlDocument doc;
77
 
    if (!doc.Load (fullPath))
78
 
      {
 
77
    if (!doc.Load (fullPath)) {
79
78
          exit (1);
80
79
          return FALSE;
81
 
      }
 
80
        }
82
81
    // start processing the XML file
83
 
    if (doc.GetRoot ()->GetName () != wxT (XML_PROGRAM))
84
 
      {
85
 
          cout << "invalid xml file" << endl;
86
 
          return FALSE;
87
 
      }
 
82
    if (doc.GetRoot ()->GetName () != wxT (XML_PROGRAM)) {
 
83
            cout << "invalid xml file" << endl;
 
84
            return FALSE;
 
85
        }
88
86
 
89
87
    wxXmlNode *program = doc.GetRoot ()->GetChildren ();
90
88
    int id = 0;
91
 
    while (program)
92
 
      {
93
 
 
94
 
          if (program->GetName () == wxT (XML_SIMDOCK))
95
 
            {
96
 
                wxXmlNode *child = program->GetChildren ();
97
 
 
98
 
                wxString path, icon, descr, name;
99
 
                while (child)
100
 
                  {
101
 
                      if (child->GetName () == wxT (XML_PATH))
102
 
                          path = child->GetNodeContent ();
103
 
                      if (child->GetName () == wxT (XML_ICON))
104
 
                          icon = child->GetNodeContent ();
105
 
                      if (child->GetName () == wxT (XML_DESCR))
106
 
                          descr = child->GetNodeContent ();
107
 
                      if (child->GetName () == wxT (XML_NAME))
108
 
                          name = child->GetNodeContent ();
109
 
                      child = child->GetNext ();
110
 
                  }
111
 
                if (!path.IsEmpty () && !icon.IsEmpty ())
112
 
                  {
113
 
                      wxImage img;
114
 
                      if (!img.LoadFile (icon))
115
 
                          {
116
 
                                img.LoadFile(questionPath);
117
 
                          }
 
89
    while (program) {
 
90
 
 
91
                if (program->GetName () == wxT (XML_SIMDOCK)) {
 
92
                        wxXmlNode *child = program->GetChildren ();
 
93
 
 
94
                        wxString path, icon, descr, name;
 
95
                        while (child) {
 
96
                                if (child->GetName () == wxT (XML_PATH))
 
97
                                        path = child->GetNodeContent ();
 
98
                                if (child->GetName () == wxT (XML_ICON))
 
99
                                        icon = child->GetNodeContent ();
 
100
                                if (child->GetName () == wxT (XML_DESCR))
 
101
                                        descr = child->GetNodeContent ();
 
102
                                if (child->GetName () == wxT (XML_NAME))
 
103
                                        name = child->GetNodeContent ();
 
104
                                child = child->GetNext ();
 
105
                        }
 
106
                        if (!path.IsEmpty () && !icon.IsEmpty ()) {
 
107
                        wxImage img;
 
108
 
 
109
                                if (icon.EndsWith(".svg")) {
 
110
                                        // we use the questionPath as placeholder for the constructor
 
111
                                        img.LoadFile(questionPath);
 
112
                                } else {
 
113
                                        if (!img.LoadFile (icon)) {
 
114
                                                img.LoadFile(questionPath);
 
115
                                        }
 
116
                                }
118
117
                            simImage *sim = new simImage (img,
119
118
                                                          icon,
120
119
                                                          path,
123
122
                                                          id++);
124
123
                            sim->w = settings->ICONW;
125
124
                            sim->h = settings->ICONH;
126
 
                            sim->y = (settings->MAXSIZE + settings->BOTTOM_BORDER) - settings->ICONH - settings->BOTTOM_BORDER; // I 
127
 
                            // know, 
128
 
                            // it's 
129
 
                            // ugly
 
125
                            sim->y = (settings->MAXSIZE + settings->BOTTOM_BORDER) - settings->ICONH - settings->BOTTOM_BORDER;
 
126
                                if (icon.EndsWith(".svg")) {
 
127
                                        sim->loadImage(icon);
 
128
                                }
130
129
 
131
130
                            list->Add (sim);
132
131
#ifdef SIMDOCK_DEBUG
133
132
                            cout << id << ":" << wx2std (name) << endl;
134
133
#endif
135
 
                  }
 
134
                    }
136
135
            }
137
136
          program = program->GetNext ();
138
137