-rw-r--r-- | libopie2/examples/opiecore/onotifydemo/onotifydemo.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/libopie2/examples/opiecore/onotifydemo/onotifydemo.cpp b/libopie2/examples/opiecore/onotifydemo/onotifydemo.cpp index a8a5717..74a8158 100644 --- a/libopie2/examples/opiecore/onotifydemo/onotifydemo.cpp +++ b/libopie2/examples/opiecore/onotifydemo/onotifydemo.cpp | |||
@@ -5,18 +5,19 @@ | |||
5 | #include <opie2/olistview.h> | 5 | #include <opie2/olistview.h> |
6 | #include <opie2/ofilenotify.h> | 6 | #include <opie2/ofilenotify.h> |
7 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
8 | using namespace Opie::Ui; | 8 | using namespace Opie::Ui; |
9 | 9 | ||
10 | /* QT */ | 10 | /* QT */ |
11 | #include <qcheckbox.h> | ||
11 | #include <qvbox.h> | 12 | #include <qvbox.h> |
12 | #include <qhbox.h> | 13 | #include <qhbox.h> |
13 | #include <qhbuttongroup.h> | 14 | #include <qhbuttongroup.h> |
14 | #include <qvbuttongroup.h> | 15 | #include <qvbuttongroup.h> |
16 | #include <qmessagebox.h> | ||
15 | #include <qpushbutton.h> | 17 | #include <qpushbutton.h> |
16 | #include <qcheckbox.h> | ||
17 | 18 | ||
18 | class DemoApp : public OApplication | 19 | class DemoApp : public OApplication |
19 | { | 20 | { |
20 | Q_OBJECT | 21 | Q_OBJECT |
21 | public: | 22 | public: |
22 | DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2 notify demo" ) | 23 | DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2 notify demo" ) |
@@ -24,13 +25,16 @@ public: | |||
24 | 25 | ||
25 | QVBox* vbox = new QVBox(); | 26 | QVBox* vbox = new QVBox(); |
26 | setMainWidget( vbox ); | 27 | setMainWidget( vbox ); |
27 | 28 | ||
28 | l = new OListView( vbox ); | 29 | l = new OListView( vbox ); |
29 | l->addColumn( "Notification Path" ); | 30 | l->addColumn( "Notification Path" ); |
30 | l->addColumn( "Trigger" ); | 31 | l->addColumn( "Trigger Type" ); |
32 | l->addColumn( "Trigger Mask" ); | ||
33 | l->setColumnAlignment( 1, AlignCenter ); | ||
34 | l->setColumnAlignment( 2, AlignCenter ); | ||
31 | 35 | ||
32 | QHBox* hbox = new QHBox( vbox ); | 36 | QHBox* hbox = new QHBox( vbox ); |
33 | 37 | ||
34 | g2 = new QVButtonGroup( "Specify Trigger Type", hbox ); | 38 | g2 = new QVButtonGroup( "Specify Trigger Type", hbox ); |
35 | //QCheckBox* c1 = new QCheckBox( "Multi", g2 ); | 39 | //QCheckBox* c1 = new QCheckBox( "Multi", g2 ); |
36 | QCheckBox* c2 = new QCheckBox( "Access", g2 ); | 40 | QCheckBox* c2 = new QCheckBox( "Access", g2 ); |
@@ -42,12 +46,13 @@ public: | |||
42 | g2->insert( c2, Access ); | 46 | g2->insert( c2, Access ); |
43 | g2->insert( c3, Modify ); | 47 | g2->insert( c3, Modify ); |
44 | g2->insert( c4, Create ); | 48 | g2->insert( c4, Create ); |
45 | g2->insert( c5, Delete ); | 49 | g2->insert( c5, Delete ); |
46 | g2->insert( c6, Rename ); | 50 | g2->insert( c6, Rename ); |
47 | g2->insert( c7, Attrib ); | 51 | g2->insert( c7, Attrib ); |
52 | connect( g2, SIGNAL( pressed(int) ), this, SLOT( modifierClicked(int) ) ); | ||
48 | 53 | ||
49 | g1 = new QVButtonGroup( "Add/Remove", hbox ); | 54 | g1 = new QVButtonGroup( "Add/Remove", hbox ); |
50 | QPushButton* plus1 = new QPushButton( "Add\n&Single", g1 ); | 55 | QPushButton* plus1 = new QPushButton( "Add\n&Single", g1 ); |
51 | QPushButton* plus2 = new QPushButton( "Add\n&Multi", g1 ); | 56 | QPushButton* plus2 = new QPushButton( "Add\n&Multi", g1 ); |
52 | QPushButton* minus = new QPushButton( "&Remove\nIt!", g1 ); | 57 | QPushButton* minus = new QPushButton( "&Remove\nIt!", g1 ); |
53 | g1->insert( plus1, 0 ); | 58 | g1->insert( plus1, 0 ); |
@@ -65,49 +70,69 @@ public: | |||
65 | showMainWidget( vbox ); | 70 | showMainWidget( vbox ); |
66 | } | 71 | } |
67 | 72 | ||
68 | public: | 73 | public: |
69 | void addTrigger( bool multi = false ) | 74 | void addTrigger( bool multi = false ) |
70 | { | 75 | { |
76 | if ( !m ) | ||
77 | { | ||
78 | QMessageBox::warning( 0, "Add Trigger", "<p>Can't add trigger without at least one selected trigger type</p>", "&Sorry", 0 ); | ||
79 | return; | ||
80 | } | ||
81 | |||
71 | QString filename = OFileDialog::getOpenFileName( OFileSelector::ExtendedAll ); | 82 | QString filename = OFileDialog::getOpenFileName( OFileSelector::ExtendedAll ); |
72 | if ( !filename.isEmpty() ) | 83 | if ( !filename.isEmpty() ) |
73 | { | 84 | { |
74 | odebug << "Filename = " << filename << oendl; | 85 | odebug << "Filename = " << filename << oendl; |
75 | new OListViewItem( l, filename, "Modify" ); | ||
76 | |||
77 | 86 | ||
87 | int fntype = m; | ||
88 | if ( multi ) fntype |=(int) Multi; | ||
78 | 89 | ||
79 | OFileNotifier::singleShot( filename, this, SLOT( trigger() ) ); | 90 | QString modifier = QString().sprintf( " = 0x%08x", fntype ); |
91 | new OListViewItem( l, filename, multi ? "MULTI" : "SINGLE", modifier ); | ||
92 | if ( !multi ) | ||
93 | OFileNotification::singleShot( filename, this, SLOT( trigger() ), (OFileNotificationType) fntype ); | ||
94 | else | ||
95 | OFileNotification::singleShot( filename, this, SLOT( trigger() ), (OFileNotificationType) fntype ); | ||
80 | } | 96 | } |
81 | else | 97 | else |
82 | { | 98 | { |
83 | odebug << "cancelled." << oendl; | 99 | odebug << "cancelled." << oendl; |
84 | } | 100 | } |
85 | } | 101 | } |
86 | 102 | ||
87 | public slots: | 103 | public slots: |
88 | 104 | void modifierClicked( int modifier ) { (int)m ^= modifier; }; | |
89 | void addSingle() { addTrigger(); }; | 105 | void addSingle() { addTrigger(); }; |
90 | void addMulti() { addTrigger( true ); }; | 106 | void addMulti() { addTrigger( true ); }; |
91 | 107 | ||
92 | void delTrigger() | 108 | void delTrigger() |
93 | { | 109 | { |
94 | QString filename( "bla" ); | 110 | QListViewItem* item = l->selectedItem(); |
95 | odebug << "Filename = " << filename << oendl; | 111 | if ( !item ) |
112 | { | ||
113 | QMessageBox::warning( 0, "Del Trigger", "<p>No trigger selected!</p>", "&Sorry", 0 ); | ||
114 | return; | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | QString filename( item->text( 0 ) ); | ||
119 | odebug << "Filename = " << filename << oendl; | ||
120 | } | ||
96 | } | 121 | } |
97 | 122 | ||
98 | void trigger() | 123 | void trigger() |
99 | { | 124 | { |
100 | owarn << "FIRE!" << oendl; | 125 | owarn << "FIRE!" << oendl; |
101 | } | 126 | } |
102 | 127 | ||
103 | private: | 128 | private: |
104 | OListView* l; | 129 | OListView* l; |
105 | QButtonGroup* g1; | 130 | QButtonGroup* g1; |
106 | QButtonGroup* g2; | 131 | QButtonGroup* g2; |
107 | int m; | 132 | OFileNotificationType m; |
108 | }; | 133 | }; |
109 | 134 | ||
110 | int main( int argc, char** argv ) | 135 | int main( int argc, char** argv ) |
111 | { | 136 | { |
112 | DemoApp* app = new DemoApp( argc, argv ); | 137 | DemoApp* app = new DemoApp( argc, argv ); |
113 | app->exec(); | 138 | app->exec(); |