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.
 
 
 
 
 

154 lines
4.3 KiB

  1. /*
  2. * blk_tree.h
  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. #ifndef __BLK_TREE_H__
  21. #define __BLK_TREE_H__
  22. #include <gtkmm.h>
  23. #include <thread>
  24. #include <vector>
  25. #include "annex.h"
  26. #include "blk_model.h"
  27. #include "blk_node.h"
  28. namespace Hopman {
  29. using namespace std;
  30. class BlkTree : public Gtk::TreeView
  31. {
  32. public:
  33. BlkTree(const Hopman::Annex&);
  34. virtual ~BlkTree ();
  35. bool get_shall_quit();
  36. class cMenu : public Gtk::Menu
  37. {
  38. public:
  39. cMenu(BlkTree*);
  40. virtual ~cMenu();
  41. void display_menu(GdkEventButton*, string, bool);
  42. private:
  43. string name;
  44. // Child widgets
  45. Gtk::MenuItem *item;
  46. virtual void on_open_new_tab(BlkTree*);
  47. virtual void on_open_new_window(BlkTree*);
  48. };
  49. string get_selected();
  50. class Worker
  51. {
  52. Worker();
  53. virtual ~Worker();
  54. private:
  55. struct BlkData { // data to manage
  56. BlkData( ) { }
  57. virtual ~BlkData() { }
  58. string path, fstype, label, uuid, partuuid;
  59. };
  60. vector< shared_ptr<Hopman::BlkNode> > pObj_Worker;
  61. void do_work(BlkTree*, const Hopman::Annex&);
  62. void stop_work();
  63. void get_data(vector< shared_ptr<Hopman::BlkNode> >&) const;
  64. static bool compareNames(shared_ptr<Hopman::BlkNode>, shared_ptr<Hopman::BlkNode>);
  65. static bool compareNodes(shared_ptr<Hopman::BlkNode>, shared_ptr<Hopman::BlkNode>);
  66. static vector<string> split_line(const string&, const string&);
  67. static void showList(struct vdev_usb_device_list*);
  68. // Synchronizes access to member data.
  69. mutable mutex m_Mutex;
  70. // Data used by both GUI thread and worker thread.
  71. bool m_first_time, m_shall_stop;
  72. // Declare the outer class as friend of the inner class:
  73. friend class BlkTree;
  74. };
  75. protected:
  76. bool on_button_press_event(GdkEventButton*) override;
  77. bool on_left_button_press_event();
  78. bool on_right_button_press_event(GdkEventButton*);
  79. bool on_middle_button_press_event(GdkEventButton*);
  80. bool on_double_click_event(GdkEventButton*);
  81. void on_mount();
  82. bool is_partition_unmounted(string);
  83. /* This is for the double click event */
  84. void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */);
  85. bool on_test_collapse_row (const Gtk::TreeModel::iterator&, const Gtk::TreeModel::Path&);
  86. void on_cursor_changed();
  87. /* Tooltip */
  88. bool on_query_tooltip(int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&);
  89. private:
  90. int X;
  91. vector< shared_ptr<Hopman::BlkNode> > pObj;
  92. Gtk::Window *m_tooltip_window;
  93. Gtk::Label m_Label;
  94. bool display_menu, do_action, m_shall_quit;
  95. string selected, ejected_icon, socket, path_to_the_helper;
  96. Worker m_Worker;
  97. thread *m_WorkerThread;
  98. // Glib:
  99. Glib::Dispatcher m_Dispatcher;
  100. // Called from the worker thread:
  101. void fill_tree();
  102. void notify();
  103. // Dispatcher handler:
  104. void get_info_from_worker_thread(const Hopman::Annex&);
  105. bool is_device_removable(shared_ptr<Hopman::BlkNode>);
  106. cMenu *m_Menu;
  107. guint cols_count;
  108. Hopman::BlkModel m_Columns;
  109. Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;
  110. Gtk::TreeModel::Row row, childrow;
  111. Gtk::TreeViewColumn* pColumn;
  112. Gtk::CellRendererProgress* cell;
  113. shared_ptr<Hopman::BlkNode> getNode(string);
  114. };
  115. typedef Hopman::BlkTree::cMenu BlkTreeCMenu;
  116. typedef Hopman::BlkTree::Worker BlkTreeWorker;
  117. } // namespace Hopman
  118. #endif // __BLK_TREE_H__