rcdiscover-gui.cc
Go to the documentation of this file.
1 /*
2  * Roboception GmbH
3  * Munich, Germany
4  * www.roboception.com
5  *
6  * Copyright (c) 2024 Roboception GmbH
7  * All rights reserved
8  *
9  * Author: Heiko Hirschmueller
10  */
11 
13 #include "rcdiscover-gui/resources/logo_128.xpm"
14 
15 #include <FL/Fl.H>
16 #include <FL/Fl_Pixmap.H>
17 #include <FL/Fl_RGB_Image.H>
18 #include <FL/fl_ask.H>
19 
20 #include <string>
21 #include <map>
22 #include <fstream>
23 
24 #ifdef WIN32
25 #include <direct.h>
26 #include <winsock2.h>
27 #endif
28 
29 class WSA
30 {
31  public:
32  WSA()
33  {
34 #ifdef WIN32
35  WSADATA wsaData;
36  WSAStartup(MAKEWORD(2, 2), &wsaData);
37 #endif
38  }
39 
40  ~WSA()
41  {
42 #ifdef WIN32
43  ::WSACleanup();
44 #endif
45  }
46 };
47 
48 int main(int argc, char *argv[])
49 {
50  WSA wsa;
51  int ret=0;
52 
53  // load configuration
54 
55  std::string name;
56 
57  int width=1180;
58  int height=394;
59  int only_rc=1;
60  std::string filter;
61  int sort_col=0;
62  bool sort_down=true;
63 
64  try
65  {
66 #ifdef WIN32
67  const char *dir=getenv("USERPROFILE");
68 
69  if (dir && dir[0] != '\0')
70  {
71  name=dir;
72  if (name[name.size()-1] != '\\')
73  {
74  name.append("\\");
75  }
76 
77  name.append("\\AppData");
78  _mkdir(name.c_str());
79  name.append("\\Local");
80  _mkdir(name.c_str());
81  name.append("\\rcdiscover");
82  _mkdir(name.c_str());
83  name.append("\\rcdiscover.txt");
84  }
85 #else
86  const char *dir=getenv("HOME");
87 
88  if (dir && dir[0] != '\0')
89  {
90  name=dir;
91  if (name[name.size()-1] != '/')
92  {
93  name.append("/");
94  }
95 
96  name.append(".config");
97  mkdir(name.c_str(), 0777);
98  name.append("/rcdiscover");
99  }
100 #endif
101 
102  if (name.size() > 0)
103  {
104  std::ifstream in(name);
105 
106  std::string key;
107  std::string value;
108  while (in >> key >> value)
109  {
110  if (value.size() > 0)
111  {
112  if (key == "width") width=std::stoi(value);
113  if (key == "height") height=std::stoi(value);
114  if (key == "only_rc") only_rc=std::stoi(value);
115  if (key == "filter") filter=value;
116  if (key == "sort_col") sort_col=std::stoi(value);
117  if (key == "sort_down") sort_down=static_cast<bool>(std::stoi(value));
118  }
119  }
120 
121  in.close();
122  }
123  }
124  catch (...)
125  {
126  // allowed to fail
127  }
128 
129  try
130  {
131  // some theme settings
132 
133  Fl::background(248, 248, 248);
134 // Fl::visible_focus(false);
135 
136  // create main window
137 
138  DiscoverWindow *window=new DiscoverWindow(width, height, only_rc, filter);
139  window->setSorting(sort_col, sort_down);
140 
141  // set icon
142 
143  Fl_Pixmap icon_xpm(logo_128_xpm);
144  Fl_RGB_Image icon_rgb(&icon_xpm, FL_GRAY);
145  window->icon(&icon_rgb);
146  window->xclass("rcdiscover");
147 
148  // show
149 
150  Fl::lock();
151  window->show(argc, argv);
152  window->doDiscover();
153 
154  ret=Fl::run();
155  Fl::unlock();
156 
157  // store configuration
158 
159  try
160  {
161  std::ofstream out(name);
162 
163  window->getSorting(sort_col, sort_down);
164 
165  out << "width " << window->w() << std::endl;
166  out << "height " << window->h() << std::endl;
167  out << "only_rc " << window->getOnlyRCValue() << std::endl;
168 
169  filter=window->getFilterValue();
170  if (filter.size() > 0)
171  {
172  out << "filter " << filter << std::endl;
173  }
174 
175  out << "sort_col " << sort_col << std::endl;
176  out << "sort_down " << sort_down << std::endl;
177 
178  out.close();
179  }
180  catch (...)
181  {
182  // allowed to fail
183  }
184 
185  // clean up resources
186 
187  delete window;
188  }
189  catch (const std::exception &ex)
190  {
191  fl_alert("%s", ex.what());
192  ret=1;
193  }
194 
195  return ret;
196 }
discover_window.h
DiscoverWindow::setSorting
void setSorting(int sort_col, bool sort_down)
Definition: discover_window.h:40
WSA
Definition: rcdiscover-gui.cc:29
DiscoverWindow::getSorting
void getSorting(int &sort_col, bool &sort_down)
Definition: discover_window.h:39
WSA::~WSA
~WSA()
Definition: rcdiscover-gui.cc:40
main
int main(int argc, char *argv[])
Definition: rcdiscover-gui.cc:48
WSA::WSA
WSA()
Definition: rcdiscover-gui.cc:32
DiscoverWindow::getFilterValue
const char * getFilterValue()
Definition: discover_window.h:43
DiscoverWindow::doDiscover
void doDiscover()
Definition: discover_window.cc:254
DiscoverWindow::getOnlyRCValue
int getOnlyRCValue()
Definition: discover_window.h:42
DiscoverWindow
Definition: discover_window.h:32


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Thu Aug 1 2024 02:55:56