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
|
#include "BobEditor.hpp"
using namespace std;
BobEditor::BobEditor() : appGrid()
{
set_events(Gdk::ALL_EVENTS_MASK);
add(appGrid);
listTargets.push_back( Gtk::TargetEntry("APP") );
listTargets.push_back( Gtk::TargetEntry("text/plain") );
GetAppGrid();
show_all_children();
}
void BobEditor::GetAppGrid()
{
// Parsing du fichier de configuration apwal
string filepath = "/home/";
filepath += getenv("USER");
filepath += "/.apwalrc.xml";
xmlpp::DomParser parser(filepath);
xmlpp::Document* doc = parser.get_document();
// Recherche des webapps
string request = "//app[(starts-with(cmdline/text(),'chromium-browser') and x>='"
+ boost::lexical_cast<std::string>(XMIN)
+ "' and x<='"
+ boost::lexical_cast<std::string>(XMAX)
+ "') or starts-with(cmdline/text(),'bobedit')]";
xmlpp::NodeSet result;
xmlpp::Element* root = doc->get_root_node();
result = root->find(request);
cout << result.size() << " apps trouvées" << endl;
// Construction des objets WebApp et de la grille
WebApp* app;
for(xmlpp::NodeSet::iterator i=result.begin(); i!=result.end(); i++) {
app = Gtk::manage(new WebApp());
xmlpp::Node::NodeList ic = dynamic_cast<xmlpp::Node*>(*i)->get_children();
for(xmlpp::Node::NodeList::iterator j=ic.begin(); j!=ic.end(); j++) {
if(dynamic_cast<xmlpp::Node*>(*j)->get_name().compare("cmdline")==0) {
xmlpp::Element* cmdNode = dynamic_cast<xmlpp::Element*>(*j);
app->SetIcon( cmdNode->get_child_text()->get_content() );
}
if(dynamic_cast<xmlpp::Node*>(*j)->get_name().compare("icon")==0) {
xmlpp::Element* iconNode = dynamic_cast<xmlpp::Element*>(*j);
app->SetIcon( "/home/k/" + iconNode->get_child_text()->get_content() );
}
if(dynamic_cast<xmlpp::Node*>(*j)->get_name().compare("x")==0) {
xmlpp::Element* xNode = dynamic_cast<xmlpp::Element*>(*j);
app->SetX( boost::lexical_cast<int>(xNode->get_child_text()->get_content())-XMIN );
}
if(dynamic_cast<xmlpp::Node*>(*j)->get_name().compare("y")==0) {
xmlpp::Element* xNode = dynamic_cast<xmlpp::Element*>(*j);
app->SetY( boost::lexical_cast<int>(xNode->get_child_text()->get_content())-YMIN );
}
}
app->drag_source_set(listTargets);
app->signal_drag_begin().connect(sigc::mem_fun(*this,&BobEditor::duh));
app->signal_drag_data_get().connect(sigc::mem_fun(*this,&BobEditor::on_drag_data_get) );
app->drag_dest_set(listTargets);
app->signal_drag_data_received().connect(sigc::mem_fun(*this,&BobEditor::on_drag_data_received) );
appGrid.attach(*app,app->GetX(),app->GetY(),1,1);
}
// Remplissage de la grille avec des WebApps vides
request = "//app[starts-with(cmdline/text(),'bobedit')]/y/text()";
cout << root << endl;
result = root->find(request);
for(xmlpp::NodeSet::iterator i=result.begin(); i!=result.end(); i++) {
YMAX = boost::lexical_cast<int>( dynamic_cast<xmlpp::TextNode*>(*i)->get_content() ) - YMIN;
}
cout << "Dernière ligne = " << YMAX << endl;
string blankIcon = "/home/";
blankIcon += getenv("USER");
blankIcon += "/.icons/apwal/theme/5.png";
for(int i=0; i<=XMAX-XMIN; i++) {
for(int j=0; j<=YMAX; j++) {
if( !appGrid.get_child_at(i,j) ) {
app = Gtk::manage(new WebApp("open","",blankIcon,i,j));
appGrid.attach(*app,i,j,1,1);
}
}
}
}
void BobEditor::duh(const Glib::RefPtr<Gdk::DragContext>& context)
{
cout << "dah" << endl;
}
void BobEditor::on_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context,
Gtk::SelectionData& selection_data, guint info,
guint time)
{
selection_data.set(selection_data.get_target(), 8 /* 8 bits format */,
(const guchar*)"I'm Data!",
9 /* the length of I'm Data! in bytes */);
}
void BobEditor::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context,
int x, int y,const Gtk::SelectionData& selection_data,
guint info, guint time)
{
const int length = selection_data.get_length();
if((length >= 0) && (selection_data.get_format() == 8))
{
std::cout << "Received \"" << selection_data.get_data_as_string()
<< "\" in label " << std::endl;
}
context->drag_finish(false, false, time);
}
BobEditor::~BobEditor()
{
} |
Partager