From 8df5e375cde169377b8e14e0b87920263b187329 Mon Sep 17 00:00:00 2001 From: Steven Tucker Date: Tue, 6 Nov 2012 11:09:51 +0000 Subject: Initial commit of Admin Panel. Has basic functionality that you might expect from the core program, escalates priviledges, loads categories and modules dynamically from configuration file, launches modules and returns to the panel once the module has completed. Works within ncurses, gtk and qt environments using the native widget set. --- modules/test.cpp | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 modules/test.cpp (limited to 'modules') diff --git a/modules/test.cpp b/modules/test.cpp new file mode 100644 index 00000000..6f3178ef --- /dev/null +++ b/modules/test.cpp @@ -0,0 +1,137 @@ +// Trivial libyui example. +// +// Compile with: +// +// g++ -I/usr/include/yui -lyui test.cpp -o test +// +#include "YUI.h" +#include "YApplication.h" +#include "YWidgetFactory.h" +#include "YDialog.h" +#include "YPushButton.h" +#include "YLayoutBox.h" +#include "YReplacePoint.h" +#include "YEvent.h" +#include "YFrame.h" +#include + +int main( int argc, char **argv ) +{ + YUI::app()->setApplicationTitle("Test module"); + YUI::app()->setApplicationIcon("/usr/share/icons/mageia.png"); + + YDialog * dialog = YUI::widgetFactory()->createPopupDialog(); + YFrame* frame = YUI::widgetFactory()->createFrame(dialog, "Test frame"); + YLayoutBox * hbox = YUI::widgetFactory()->createHBox(frame); + YFrame* lframe = YUI::widgetFactory()->createFrame(hbox, "Left frame"); + YFrame* rframe = YUI::widgetFactory()->createFrame(hbox, "Right frame"); + // here we change the widget + YReplacePoint* replacePoint = YUI::widgetFactory()->createReplacePoint(rframe); + + YLayoutBox * vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + YLayoutBox * vbox = YUI::widgetFactory()->createVBox( lframe ); +// vbox->setSize( 1000, 1000 ); + lframe->setWeight(YD_HORIZ, 25); + rframe->setWeight(YD_HORIZ, 75); + YUI::widgetFactory()->createLabel ( vbox, "Hello, World!" ); + YPushButton* addButton = YUI::widgetFactory()->createPushButton( vbox, "Add Button" ); + YPushButton* removeButton = YUI::widgetFactory()->createPushButton( vbox, "Remove Button" ); + YPushButton* exitButton = YUI::widgetFactory()->createPushButton( vbox, "&Exit" ); + YUI::widgetFactory()->createSpacing( vbox, YD_VERT, true, 1.0 ); + + //YPushButton* testButton = YUI::widgetFactory()->createPushButton( vbox, "&Cannot be added" ); + //testButton->hide(); <-- Angelo, I could not see this call in the api + + int bnum = 0; + std::vectorbuttons; + + for (;;) + { + YEvent* event = dialog->waitForEvent(); + // Check for window close + if (event->eventType() == YEvent::CancelEvent) + { + break; + } + + // Check for Exit button push + if(event->widget() == (YWidget*)exitButton ) { + break; + }; + + if(event->widget() == (YWidget*)addButton ) { + if(bnum < 6) { + dialog->startMultipleChanges(); + replacePoint->deleteChildren(); + vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + bnum++; + buttons.clear(); + for (int i=0; i < bnum; ++i) + { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); + } + replacePoint->showChild(); + dialog->recalcLayout(); + dialog->doneMultipleChanges(); + } + else if (bnum == 6) + { + dialog->startMultipleChanges(); + replacePoint->deleteChildren(); + vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + buttons.clear(); + for (int i=0; i < bnum; ++i) + { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); + } + YUI::widgetFactory()->createSpacing( vbox_rframe, YD_VERT, false, 1.0 ); + replacePoint->showChild(); + dialog->recalcLayout(); + dialog->doneMultipleChanges(); + } + } + if(event->widget() == (YWidget*)removeButton ) { + if (bnum > 0) + { + dialog->startMultipleChanges(); + replacePoint->deleteChildren(); + vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + bnum--; + buttons.clear(); + for (int i=0; i < bnum; ++i) + { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); + } + replacePoint->showChild(); + dialog->recalcLayout(); + dialog->doneMultipleChanges(); + } + } + + + for(int i = 0; i < bnum; ++i) + { + if (event->widget() == (YWidget*)buttons[i]) { + dialog->startMultipleChanges(); + replacePoint->deleteChildren(); + vbox_rframe = YUI::widgetFactory()->createVBox( replacePoint ); + bnum--; + buttons.clear(); + for (int i=0; i < bnum; ++i) + { + YPushButton* tmpB = YUI::widgetFactory()->createPushButton( vbox_rframe, "Delete Me" ); + buttons.push_back(tmpB); + } + replacePoint->showChild(); + dialog->recalcLayout(); + dialog->doneMultipleChanges(); + break; + } + } + } + + dialog->destroy(); +} -- cgit v1.2.1