Hotplug partition manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

116 lines
3.2 KiB

  1. /*
  2. * annex.cpp
  3. * Copyright (C) 2021 Aitor Cuadrado Zubizarreta <aitor_czr@gnuinos.org>
  4. *
  5. * This program is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * See the LICENSE file. *
  19. */
  20. #include <unistd.h>
  21. #include <cstdio>
  22. #include <gtkmm.h>
  23. #include <vector>
  24. #include "annex.h"
  25. namespace Hopman
  26. {
  27. Annex::Annex(int argc, char **argv, int x, int y)
  28. {
  29. for(int i=0; i<argc; i++)
  30. args.push_back(string(argv[i]));
  31. pid_t pid = getpid();
  32. char *c = NULL;
  33. if (asprintf(&c, "%jd", (intmax_t) pid) != -1) {
  34. mypid = string(c);
  35. free(c); // cleanup when done.
  36. } else
  37. cerr << "Unable to get the pid\n";
  38. x_screen = x;
  39. y_screen = y;
  40. watch_dir = "/dev/";
  41. socket = "/tmp/" + mypid + "_hopman.socket";
  42. helper_socket = "/tmp/" + mypid + "_hopman_helper.socket";
  43. worker_socket = "/tmp/" + mypid + "_hopman_worker.socket";
  44. get_current_path();
  45. set_pixmaps();
  46. set_path_to_the_helper();
  47. }
  48. Annex::~Annex()
  49. {
  50. remove( socket.c_str() );
  51. remove( helper_socket.c_str() );
  52. remove( worker_socket.c_str() );
  53. }
  54. // If we launch the application clicking on the applet, the path will be defined in the .desktop file
  55. // In our case Path=/dev
  56. void Annex::get_current_path()
  57. {
  58. char current_working_dir[1024] = {0};
  59. getcwd(current_working_dir, 1024);
  60. current_path = string(current_working_dir);
  61. }
  62. void Annex::set_pixmaps()
  63. {
  64. string str = "/usr/share/pixmaps/hopman.png";
  65. Glib::RefPtr<Gio::File> ref_path = Gio::File::create_for_path( str );
  66. if ( ref_path->query_exists() )
  67. app_icon = str;
  68. else
  69. cerr << app_icon + " , not found!" << endl;
  70. str = "/usr/share/hopman/icons/usb-eject-32x32.png";
  71. ref_path = Gio::File::create_for_path( str );
  72. if ( ref_path->query_exists() )
  73. eject_icon = str;
  74. else
  75. cerr << eject_icon + " , not found!" << endl;
  76. str = "/usr/share/hopman/icons/usb-ejected-32x32.png";
  77. ref_path = Gio::File::create_for_path( str );
  78. if ( ref_path->query_exists() )
  79. ejected_icon = str;
  80. else
  81. cerr << ejected_icon + " , not found!" << endl;
  82. str = "/usr/share/hopman/icons/warning.png";
  83. ref_path = Gio::File::create_for_path( str );
  84. if ( ref_path->query_exists() )
  85. warning_icon = str;
  86. else
  87. cerr << warning_icon + " , not found!" << endl;
  88. }
  89. void Annex::set_path_to_the_helper()
  90. {
  91. string path = current_path + "/suid";
  92. Glib::RefPtr<Gio::File> ref_path = Gio::File::create_for_path( path );
  93. if ( ref_path->query_exists() )
  94. path_to_the_helper = path;
  95. else
  96. cerr << "Helper not found!" << endl;
  97. }
  98. } // namespace Hopman