File: demo-common.cc

package info (click to toggle)
gtkmm3.0 3.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 159,024 kB
  • ctags: 22,555
  • sloc: xml: 107,819; sh: 11,425; cpp: 7,074; makefile: 241; perl: 235
file content (63 lines) | stat: -rw-r--r-- 1,452 bytes parent folder | download
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
#include "demo-common.h"
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h> //For Glib::build_filename().
#include <iostream>

#ifdef GLIBMM_WIN32

#undef DEMOCODEDIR

// TODO: Apply scorched earth tactics on code below.
static char *
get_democodedir(void)
{
  static char *result = NULL;

  if (result == NULL)
    {
      result = g_win32_get_package_installation_directory_of_module(0);
      if (result == NULL)
	result = "unknown-location";

      result = g_strconcat (result, "\\share\\gtkmm-3.0\\demo", NULL);
    }

  return result;
}

#define DEMOCODEDIR get_democodedir()

#endif // GLIBMM_WIN32

/**
 * demo_find_file:
 * @base: base filename
 * 
 * Looks for @base first in the current directory, then in the
 * location where gtkmm will be installed on make install,
 * returns the first file found.
 * 
 * Return value: the filename, if found, else throws a Glib::FileError.
 **/
std::string demo_find_file(const std::string& base)
{
  if(Glib::file_test("gtk-logo-rgb.gif", Glib::FILE_TEST_EXISTS) &&
      Glib::file_test (base, Glib::FILE_TEST_EXISTS))
  {
    return base;
  }
  else
  {
    std::string filename = Glib::build_filename(DEMOCODEDIR, base);
    if(!Glib::file_test(filename, Glib::FILE_TEST_EXISTS))
    {
      Glib::ustring msg = "Cannot find demo data file " + base;  

      throw Glib::FileError(Glib::FileError::NO_SUCH_ENTITY, msg);
      return Glib::ustring();
    }
    
    return filename;
  }
}