summaryrefslogtreecommitdiffstats
path: root/vmchooser/SWindow.cxx
blob: 8df3a7887173a17d5e585b63aee5aae0abfd6327 (plain) (blame)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

#include "inc/SWindow.h"

#include <iostream>

#include <img/gnome_32.xpm>
#include <img/kde_32.xpm>
#include <img/linux_32.xpm>
#include <img/xp_32.xpm>
#include <img/xp_locked_32.xpm>
#include <img/xfce_32.xpm>


using namespace fltk;
using namespace std;

/********************************************************
 * Callback for ReturnButton at the bottom of the GUI
 * ----------------------------------------------------
 * Should start chosen session entry -> if something is selected
 *********************************************************/
void SWindow::cb_return()
{
  if(curr != 0 && curr->user_data()) {
    DataEntry* dat = (DataEntry*) curr->user_data();
    runImage(curr, dat);
  }
}


/*******************************************************
 *  Callback for Selection-Browser in the center
 * ----------------------------------------------------
 * Changes info-Text at the bottom
 *******************************************************/
void SWindow::cb_select()
{
  sel.select_only_this();
  if (sel.item_is_parent() )
    {
      sel.set_item_opened(true);
    }
  if( curr == sel.item() ) {
    //Doubleclick
    cout << ((DataEntry*)curr->user_data())->short_description << endl;
    if(curr->user_data()) {
      runImage(curr, (DataEntry*) curr->user_data() );
    }
    return;
  }
  curr = (Item*) sel.item();
//   if(curr->user_data()) {
//     DataEntry* dat = (DataEntry*) curr->user_data();
//     info.text(dat->description.c_str());
//   }
}

/**
 * Callback for TextDisplay at the bottom - change it?
 */
void SWindow::cb_info()
{
}


/**********************************************************
 * Put entries in a Linux-Session Group into Browser
 *********************************************************/
void SWindow::set_lin_entries(DataEntry** ent, char* slxgroup)
{
  this->lin_ent = ent;
  lin_entgroup = (ItemGroup*) sel.add_group("LINUX DESKTOP", &sel);

  for (int i=0; ent[i] != NULL; i++)
    {
      if( ent[i]->pools.empty() || ent[i]->pools.find(slxgroup) != string::npos) {
        Item* w= (Item*)sel.add_leaf(ent[i]->short_description.c_str() , lin_entgroup, (void*)ent[i] );
        
        ((Widget*) w)->image(new xpmImage(get_symbol(ent[i])));
        w->tooltip(ent[i]->description.c_str());
        w->callback(&runImage, (void*)ent[i]);
      }
    }

  lin_entgroup->end();
}


/**********************************************************
 * Put entries in a VMWARE-Session Group into Browser
 *********************************************************/
void SWindow::set_entries(DataEntry** ent, char* slxgroup)
{
  this->ent = ent;
  sort_entries();
  
  entgroup =  (ItemGroup*)sel.add_group("VMWARE SESSIONS", &sel);
  for (int i=0; ent[i] != NULL; i++)
    {
      if(ent[i]->pools.empty() || ent[i]->pools.find(slxgroup) != string::npos) {
        Item* w= (Item*)sel.add_leaf(ent[i]->short_description.c_str(), entgroup, (void*)ent[i] );
        
        xpmImage* xpm = new xpmImage(get_symbol(ent[i]));
        ((Widget*) w)->image(xpm);
        w->tooltip(ent[i]->description.c_str());
        w->callback(&runImage, (void*)ent[i]);
      }
    }

  entgroup->end();
}

/**************************************************************
 * free arrays (which are dynamically allocated)
 **************************************************************/
void SWindow::free_entries()
{
  for (int i=0; ent[i] != NULL; i++)
    {
      free(ent[i]);
    }
  free(ent);
}



/******************************************************
 * Small helper function to unfold the 2 parent groups
 ******************************************************/
void SWindow::unfold_entries() {
  sel.goto_index(0);
  if(sel.item_is_parent() ) {
    sel.set_item_opened(true);
  }
  sel.goto_index(1);
  if(sel.item_is_parent() ) {
    sel.set_item_opened(true);
  }
  sel.deselect();
}


/******************************************************
 * Helper function to get symbols for entries
 ******************************************************/
char** SWindow::get_symbol(DataEntry* dat) {
  if(dat->imgtype == VMWARE) {
    if(dat->locked) {
    	return xp_locked_32_xpm;
    }
    else {
    	return xp_32_xpm;
    }
  }
  if(dat->imgtype == LINUX) {
    if(dat->short_description.find("KDE")!= string::npos) {
    	return kde_32_xpm;
    }
    if(dat->short_description.find("GNOME")!= string::npos) {
      return gnome_32_xpm;
    }
    if(dat->short_description.find("Xfce")!= string::npos) {
      return xfce_32_xpm;
    }
    return linux_32_xpm;
  }
  return xp_32_xpm;
}


/******************************************************
 * Sort entries to consider priorities
 ******************************************************/
void SWindow::sort_entries() {
  if(this->ent == NULL ) {
    return;
  }
  DataEntry* ptr;
  
  // worst case sort - but it is enough for this few entries
  for(int i=0; ent[i] != '\0'; i++) {
    for(int j=0; ent[j] != '\0'; j++) {
      if(ent[j]->priority > ent[i]->priority && j>i) {
        // swap element i with j (as i is alway larger j)
        ptr = ent[i];
        ent[i] = ent[j];
        ent[j] = ptr;
      }
    }
  }
}