Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Shortcut add-on: change to accomodate tracker add-ons

* Ignore shortcuts regardings tracker add-ons. Its settings file is now shared
with Tracker, and those are now handled by Tracker.
* Use a BPathMonitor as specified in a TODO to check the presence and changes on
the settings file. (#6278)
* Use a message to ask Tracker to launch/open folders as specified in TODO
  • Loading branch information...
commit 1412a36abcf4b4e7a7e652a19c4a70b3c2227c06 1 parent 56ea7a1
stpere authored July 11, 2013
2  src/add-ons/input_server/filters/shortcut_catcher/Jamfile
@@ -2,6 +2,8 @@ SubDir HAIKU_TOP src add-ons input_server filters shortcut_catcher ;
2 2
 
3 3
 SetSubDirSupportedPlatformsBeOSCompatible ;
4 4
 
  5
+UsePrivateHeaders storage ;
  6
+
5 7
 #	Common files used here and in the app
6 8
 StaticLibrary libshortcuts_shared.a :
7 9
 	BitFieldTesters.cpp
66  src/add-ons/input_server/filters/shortcut_catcher/KeyCommandMap.cpp
@@ -14,9 +14,12 @@
14 14
 #include <Beep.h>
15 15
 #include <Entry.h>
16 16
 #include <File.h>
  17
+#include <FindDirectory.h>
17 18
 #include <MessageFilter.h>
18 19
 #include <NodeMonitor.h>
19 20
 #include <OS.h>
  21
+#include <Path.h>
  22
+#include <PathMonitor.h>
20 23
 #include <WindowScreen.h>
21 24
 
22 25
 #include "BitFieldTesters.h"
@@ -71,20 +74,19 @@ KeyCommandMap::KeyCommandMap(const char* file)
71 74
 	strcpy(fFileName, file);
72 75
 
73 76
 	BEntry fileEntry(fFileName);
74  
-	// TODO: Using a BPathMonitor would be preferable. See discussion linked off
75  
-	// ticket #6278.
76  
-	if (!fileEntry.Exists())
77  
-		BFile file(fFileName, B_READ_ONLY | B_CREATE_FILE);
78  
-	
79  
-	if (fileEntry.InitCheck() == B_NO_ERROR) {
80  
-		node_ref nref;
81 77
 
82  
-		if (fileEntry.GetNodeRef(&nref) == B_NO_ERROR)
83  
-			watch_node(&nref, B_WATCH_STAT, this);
  78
+	BEntry parent;
  79
+	BPath parentPath;
  80
+	if (fileEntry.GetParent(&parent) == B_OK
  81
+		&& parent.GetPath(&parentPath) == B_OK) {
  82
+		BPrivate::BPathMonitor::StartWatching(parentPath.Path(),
  83
+			B_WATCH_STAT | B_WATCH_FILES_ONLY, this);
84 84
 	}
85 85
 
86  
-	BMessage msg(FILE_UPDATED);
87  
-	PostMessage(&msg);
  86
+	if (fileEntry.InitCheck() == B_NO_ERROR) {
  87
+		BMessage msg(FILE_UPDATED);
  88
+		PostMessage(&msg);
  89
+	}
88 90
 
89 91
 	fPort = create_port(1, SHORTCUTS_CATCHER_PORT_NAME);
90 92
 	_PutMessageToPort();
@@ -100,7 +102,7 @@ KeyCommandMap::~KeyCommandMap()
100 102
 	for (int i = fInjects.CountItems() - 1; i >= 0; i--)
101 103
 		delete (BMessage*)fInjects.ItemAt(i);
102 104
 
103  
-	stop_watching(this);
  105
+	BPrivate::BPathMonitor::StopWatching(BMessenger(this, this));
104 106
 		// don't know if this is necessary, but it can't hurt
105 107
 	_DeleteHKSList(fSpecs);
106 108
 	delete [] fFileName;
@@ -219,7 +221,21 @@ KeyCommandMap::MessageReceived(BMessage* msg)
219 221
 			_PutMessageToPort();
220 222
 			break;
221 223
 
222  
-		case B_NODE_MONITOR:
  224
+		case B_PATH_MONITOR:
  225
+		{
  226
+			const char* path = "";
  227
+			// only fall through for appropriate file
  228
+			if (!(msg->FindString("path", &path) == B_OK
  229
+					&& strcmp(path, fFileName) == 0)) {
  230
+				dev_t device;
  231
+				ino_t node;
  232
+				if (msg->FindInt32("device", &device) != B_OK
  233
+					&& msg->FindInt64("node", &node) != B_OK
  234
+					&& device != fNodeRef.device
  235
+					&& node != fNodeRef.node)
  236
+					break;
  237
+			}
  238
+		}
223 239
 		case FILE_UPDATED:
224 240
 		{
225 241
 			BMessage fileMsg;
@@ -231,6 +247,7 @@ KeyCommandMap::MessageReceived(BMessage* msg)
231 247
 				// defaults to no deletion
232 248
 				BList* oldList = NULL;
233 249
 
  250
+				file.GetNodeRef(&fNodeRef);
234 251
 				int i = 0;
235 252
 				BMessage msg;
236 253
 				while (fileMsg.FindMessage("spec", i++, &msg) == B_OK) {
@@ -241,6 +258,27 @@ KeyCommandMap::MessageReceived(BMessage* msg)
241 258
 					if (msg.FindInt32("key", (int32*) &key) == B_OK
242 259
 						&& msg.FindMessage("act", &actMsg) == B_OK
243 260
 						&& msg.FindMessage("modtester", &testerMsg) == B_OK) {
  261
+						
  262
+						// Leave handling of add-ons shortcuts to Tracker
  263
+						BString command;
  264
+						if (actMsg.FindString("largv", &command) == B_OK) {
  265
+							BPath path;
  266
+							if (find_directory(B_SYSTEM_ADDONS_DIRECTORY, &path) == B_OK) {
  267
+								path.Append("Tracker/");
  268
+								if (command.FindFirst(path.Path()) != B_ERROR)
  269
+									continue;
  270
+							}
  271
+							if (find_directory(B_COMMON_ADDONS_DIRECTORY, &path) == B_OK) {
  272
+								path.Append("Tracker/");
  273
+								if (command.FindFirst(path.Path()) != B_ERROR)
  274
+									continue;
  275
+							}
  276
+							if (find_directory(B_USER_ADDONS_DIRECTORY, &path) == B_OK) {
  277
+								path.Append("Tracker/");
  278
+								if (command.FindFirst(path.Path()) != B_ERROR)
  279
+									continue;
  280
+							}
  281
+						}
244 282
 						BArchivable* archive = instantiate_object(&testerMsg);
245 283
 						if (BitFieldTester* tester
246 284
 								= dynamic_cast<BitFieldTester*>(archive)) {
@@ -282,7 +320,7 @@ KeyCommandMap::_DeleteHKSList(BList* l)
282 320
 	if (l != NULL) {
283 321
 		int num = l->CountItems();
284 322
 		for (int i = 0; i < num; i++)
285  
-			delete ((hks*) l->ItemAt(i));
  323
+			delete ((hks*) l->ItemAt(0));
286 324
 		delete l;
287 325
 	}
288 326
 }
2  src/add-ons/input_server/filters/shortcut_catcher/KeyCommandMap.h
@@ -18,6 +18,7 @@
18 18
 #include <Messenger.h>
19 19
 #include <Message.h>
20 20
 #include <MessageFilter.h>
  21
+#include <Node.h>
21 22
 
22 23
 // Maps BMessages to ShortcutsSpecs!
23 24
 // The thread here gets file update messages, and updates
@@ -49,6 +50,7 @@ class KeyCommandMap : public BLooper {
49 50
 				
50 51
 				port_id 			fPort;
51 52
 				char*				fFileName;
  53
+				node_ref			fNodeRef;
52 54
 				BLocker 			fSyncSpecs;	// locks the lists below
53 55
 				BList 				fInjects;
54 56
 				BList*	 			fSpecs; 
28  src/add-ons/input_server/filters/shortcut_catcher/ParseCommandLine.cpp
@@ -26,9 +26,10 @@
26 26
 #include <SupportKit.h>
27 27
 
28 28
 
  29
+const char *kTrackerSignature = "application/x-vnd.Be-TRAK";
  30
+
29 31
 // This char is used to hold words together into single words...
30 32
 #define GUNK_CHAR 0x01
31  
-#define PATHTOTRACKER "/system/Tracker"
32 33
 
33 34
 // Turn all spaces that are not-to-be-counted-as-spaces into GUNK_CHAR chars.
34 35
 static void
@@ -219,7 +220,6 @@ CloneArgv(char** argv)
219 220
 }
220 221
 
221 222
 
222  
-
223 223
 BString
224 224
 ParseArgvZeroFromString(const char* command)
225 225
 {
@@ -299,24 +299,22 @@ LaunchCommand(char** argv, int32 argc)
299 299
 		// than launch.
300 300
 		BDirectory testDir(&entry);
301 301
 		if (testDir.InitCheck() == B_NO_ERROR) {
302  
-			// Hack way to do this--really I should be able to do this by 
303  
-			// sending a BMessage. But how? When I finally get my copy of the
304  
-			// BeOS Bible, maybe then I'll find out.
305  
-			BPath trackerPath;
306  
-			if (find_directory(B_SYSTEM_DIRECTORY, &trackerPath) != B_OK
307  
-				|| trackerPath.Append("Tracker") != B_OK) {
308  
-				return B_ENTRY_NOT_FOUND;
309  
-			}
310  
-			BString cmd(trackerPath.Path());
311  
-			cmd << " '" << argv[0] << "'";
312  
-			system(cmd.String());
313  
-			return B_NO_ERROR;
  302
+			entry_ref ref;
  303
+			status_t status = entry.GetRef(&ref);
  304
+			if (status < B_OK)
  305
+				return status;
  306
+
  307
+			BMessenger target(kTrackerSignature);
  308
+			BMessage message(B_REFS_RECEIVED);
  309
+			message.AddRef("refs", &ref);
  310
+
  311
+			return target.SendMessage(&message);
314 312
 		} else {
315 313
 			// It's not a directory. Must be a file.
316 314
 			entry_ref ref;
317 315
 			if (entry.GetRef(&ref) == B_NO_ERROR) {
318 316
 				if (argc > 1) 
319  
-					be_roster->Launch(&ref, argc-1, &argv[1]);
  317
+					be_roster->Launch(&ref, argc - 1, &argv[1]);
320 318
 				else
321 319
 					be_roster->Launch(&ref);
322 320
 				return B_NO_ERROR;

0 notes on commit 1412a36

Please sign in to comment.
Something went wrong with that request. Please try again.