author | mickeyl <mickeyl> | 2004-04-18 18:25:24 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-18 18:25:24 (UTC) |
commit | df539f67050ebe61b5dc589f9c138bb9ef1719f6 (patch) (unidiff) | |
tree | 7baa2dc1e44be92dec2736b8205f9642fffc4302 /libopie2/examples/opiecore | |
parent | 56f49e8293110e488f3ea6bc6dad282981c81d4b (diff) | |
download | opie-df539f67050ebe61b5dc589f9c138bb9ef1719f6.zip opie-df539f67050ebe61b5dc589f9c138bb9ef1719f6.tar.gz opie-df539f67050ebe61b5dc589f9c138bb9ef1719f6.tar.bz2 |
the notifier interface is shaping up
Brad: I sorted the "DN_xxx undeclared" issue out, please test
-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 | |||
@@ -1,119 +1,144 @@ | |||
1 | /* OPIE */ | 1 | /* OPIE */ |
2 | #include <opie2/odebug.h> | 2 | #include <opie2/odebug.h> |
3 | #include <opie2/oapplication.h> | 3 | #include <opie2/oapplication.h> |
4 | #include <opie2/ofiledialog.h> | 4 | #include <opie2/ofiledialog.h> |
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" ) |
23 | { | 24 | { |
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 ); |
37 | QCheckBox* c3 = new QCheckBox( "Modify", g2 ); | 41 | QCheckBox* c3 = new QCheckBox( "Modify", g2 ); |
38 | QCheckBox* c4 = new QCheckBox( "Create", g2 ); | 42 | QCheckBox* c4 = new QCheckBox( "Create", g2 ); |
39 | QCheckBox* c5 = new QCheckBox( "Delete", g2 ); | 43 | QCheckBox* c5 = new QCheckBox( "Delete", g2 ); |
40 | QCheckBox* c6 = new QCheckBox( "Rename", g2 ); | 44 | QCheckBox* c6 = new QCheckBox( "Rename", g2 ); |
41 | QCheckBox* c7 = new QCheckBox( "Attrib", g2 ); | 45 | QCheckBox* c7 = new QCheckBox( "Attrib", g2 ); |
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 ); |
54 | g1->insert( plus2, 1 ); | 59 | g1->insert( plus2, 1 ); |
55 | g1->insert( minus, 2 ); | 60 | g1->insert( minus, 2 ); |
56 | connect( plus1, SIGNAL( clicked() ), this, SLOT( addSingle() ) ); | 61 | connect( plus1, SIGNAL( clicked() ), this, SLOT( addSingle() ) ); |
57 | connect( plus2, SIGNAL( clicked() ), this, SLOT( addMulti() ) ); | 62 | connect( plus2, SIGNAL( clicked() ), this, SLOT( addMulti() ) ); |
58 | connect( minus, SIGNAL( clicked() ), this, SLOT( delTrigger() ) ); | 63 | connect( minus, SIGNAL( clicked() ), this, SLOT( delTrigger() ) ); |
59 | 64 | ||
60 | g1->show(); | 65 | g1->show(); |
61 | g2->show(); | 66 | g2->show(); |
62 | l->show(); | 67 | l->show(); |
63 | hbox->show(); | 68 | hbox->show(); |
64 | vbox->show(); | 69 | vbox->show(); |
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(); |
114 | 139 | ||
115 | return 0; | 140 | return 0; |
116 | 141 | ||
117 | } | 142 | } |
118 | 143 | ||
119 | #include "moc/onotifydemo.moc" | 144 | #include "moc/onotifydemo.moc" |