2005-05-23 04:58:42 +04:00
|
|
|
/*
|
|
|
|
Open Tracker License
|
|
|
|
|
|
|
|
Terms and Conditions
|
|
|
|
|
|
|
|
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice applies to all licensees
|
|
|
|
and shall be included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
|
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of Be Incorporated shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings in
|
|
|
|
this Software without prior written authorization from Be Incorporated.
|
|
|
|
|
|
|
|
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
|
|
|
|
of Be Incorporated in the United States and other countries. Other brand product
|
|
|
|
names are registered trademarks or trademarks of their respective holders.
|
|
|
|
All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
#include <errno.h>
|
2005-05-23 04:58:42 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-06-14 14:57:09 +04:00
|
|
|
#include <sys/resource.h>
|
2005-05-23 04:58:42 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
#include "Tracker.h"
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
#include <Alert.h>
|
|
|
|
#include <Autolock.h>
|
2010-07-13 16:39:53 +04:00
|
|
|
#include <Catalog.h>
|
2005-05-23 04:58:42 +04:00
|
|
|
#include <Debug.h>
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <fs_attr.h>
|
|
|
|
#include <fs_info.h>
|
|
|
|
#include <image.h>
|
2010-07-13 16:39:53 +04:00
|
|
|
#include <Locale.h>
|
2005-05-23 04:58:42 +04:00
|
|
|
#include <MenuItem.h>
|
|
|
|
#include <NodeInfo.h>
|
|
|
|
#include <NodeMonitor.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#include <Roster.h>
|
|
|
|
#include <StopWatch.h>
|
|
|
|
#include <Volume.h>
|
|
|
|
#include <VolumeRoster.h>
|
|
|
|
|
|
|
|
#include "Attributes.h"
|
|
|
|
#include "AutoLock.h"
|
|
|
|
#include "AutoMounterSettings.h"
|
|
|
|
#include "BackgroundImage.h"
|
|
|
|
#include "Bitmaps.h"
|
|
|
|
#include "Commands.h"
|
|
|
|
#include "ContainerWindow.h"
|
|
|
|
#include "DeskWindow.h"
|
|
|
|
#include "FindPanel.h"
|
|
|
|
#include "FSClipboard.h"
|
|
|
|
#include "FSUtils.h"
|
|
|
|
#include "InfoWindow.h"
|
|
|
|
#include "MimeTypes.h"
|
|
|
|
#include "MimeTypeList.h"
|
|
|
|
#include "NodePreloader.h"
|
|
|
|
#include "OpenWithWindow.h"
|
|
|
|
#include "PoseView.h"
|
|
|
|
#include "QueryContainerWindow.h"
|
|
|
|
#include "StatusWindow.h"
|
|
|
|
#include "TrackerSettings.h"
|
|
|
|
#include "TrashWatcher.h"
|
|
|
|
#include "FunctionObject.h"
|
|
|
|
#include "TrackerSettings.h"
|
|
|
|
#include "TrackerSettingsWindow.h"
|
|
|
|
#include "TaskLoop.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
#include "Utilities.h"
|
|
|
|
#include "VolumeWindow.h"
|
|
|
|
|
|
|
|
// prototypes for some private kernel calls that will some day be public
|
2007-10-16 00:13:55 +04:00
|
|
|
#ifndef _IMPEXP_ROOT
|
|
|
|
# define _IMPEXP_ROOT
|
2005-05-23 04:58:42 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const int32 DEFAULT_MON_NUM = 4096;
|
|
|
|
// copied from fsil.c
|
|
|
|
|
|
|
|
const int8 kOpenWindowNoFlags = 0;
|
|
|
|
const int8 kOpenWindowMinimized = 1;
|
|
|
|
const int8 kOpenWindowHasState = 2;
|
|
|
|
|
|
|
|
const uint32 PSV_MAKE_PRINTER_ACTIVE_QUIETLY = 'pmaq';
|
|
|
|
// from pr_server.h
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
NodePreloader* gPreloader = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2010-01-31 03:25:10 +03:00
|
|
|
class LaunchLooper : public BLooper {
|
|
|
|
public:
|
|
|
|
LaunchLooper()
|
|
|
|
:
|
|
|
|
BLooper("launch looper")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
2012-07-28 03:07:09 +04:00
|
|
|
MessageReceived(BMessage* message)
|
2010-01-31 03:25:10 +03:00
|
|
|
{
|
2012-07-28 03:07:09 +04:00
|
|
|
void (*function)(const entry_ref*, const BMessage*, bool);
|
2010-01-31 03:25:10 +03:00
|
|
|
BMessage refs;
|
|
|
|
bool openWithOK;
|
|
|
|
entry_ref appRef;
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
if (message->FindPointer("function", (void**)&function) != B_OK
|
2010-01-31 03:25:10 +03:00
|
|
|
|| message->FindMessage("refs", &refs) != B_OK
|
|
|
|
|| message->FindBool("openWithOK", &openWithOK) != B_OK) {
|
|
|
|
printf("incomplete launch message\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->FindRef("appRef", &appRef) == B_OK)
|
|
|
|
function(&appRef, &refs, openWithOK);
|
|
|
|
else
|
|
|
|
function(NULL, &refs, openWithOK);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BLooper* gLaunchLooper = NULL;
|
|
|
|
|
2010-01-31 03:25:10 +03:00
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
InitIconPreloader()
|
|
|
|
{
|
|
|
|
static int32 lock = 0;
|
|
|
|
|
|
|
|
if (atomic_add(&lock, 1) != 0) {
|
|
|
|
// Just wait for the icon cache to be instantiated
|
2009-06-14 14:57:09 +04:00
|
|
|
int32 tries = 20;
|
2005-05-23 04:58:42 +04:00
|
|
|
while (IconCache::sIconCache == NULL && tries-- > 0)
|
|
|
|
snooze(10000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IconCache::sIconCache != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// only start the node preloader if its Tracker or the Deskbar itself - don't
|
|
|
|
// start it for file panels
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
bool preload = dynamic_cast<TTracker*>(be_app) != NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
if (!preload) {
|
|
|
|
// check for deskbar
|
|
|
|
app_info info;
|
|
|
|
if (be_app->GetAppInfo(&info) == B_OK
|
|
|
|
&& !strcmp(info.signature, kDeskbarSignature))
|
|
|
|
preload = true;
|
|
|
|
}
|
|
|
|
if (preload)
|
|
|
|
gPreloader = NodePreloader::InstallNodePreloader("NodePreloader", be_app);
|
|
|
|
|
|
|
|
IconCache::sIconCache = new IconCache();
|
|
|
|
|
|
|
|
atomic_add(&lock, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
|
|
|
|
uint32
|
2012-07-28 03:07:09 +04:00
|
|
|
GetVolumeFlags(Model* model)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
fs_info info;
|
|
|
|
if (model->IsVolume()) {
|
|
|
|
// search for the correct volume
|
|
|
|
int32 cookie = 0;
|
|
|
|
dev_t device;
|
|
|
|
while ((device = next_dev(&cookie)) >= B_OK) {
|
|
|
|
if (fs_stat_dev(device,&info))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!strcmp(info.volume_name,model->Name()))
|
|
|
|
return info.flags;
|
|
|
|
}
|
|
|
|
return B_FS_HAS_ATTR;
|
|
|
|
}
|
|
|
|
if (!fs_stat_dev(model->NodeRef()->device,&info))
|
|
|
|
return info.flags;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
return B_FS_HAS_ATTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
2012-04-16 23:31:22 +04:00
|
|
|
#undef B_TRANSLATION_CONTEXT
|
|
|
|
#define B_TRANSLATION_CONTEXT "Tracker"
|
2010-07-13 16:39:53 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::TTracker()
|
|
|
|
: BApplication(kTrackerSignature),
|
|
|
|
fSettingsWindow(NULL)
|
|
|
|
{
|
2009-06-14 14:57:09 +04:00
|
|
|
// set the cwd to /boot/home, anything that's launched
|
|
|
|
// from Tracker will automatically inherit this
|
2005-05-23 04:58:42 +04:00
|
|
|
BPath homePath;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (find_directory(B_USER_DIRECTORY, &homePath) == B_OK)
|
|
|
|
chdir(homePath.Path());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
|
|
|
// ask for a bunch more file descriptors so that nested copying works well
|
|
|
|
struct rlimit rl;
|
|
|
|
rl.rlim_cur = 512;
|
|
|
|
rl.rlim_max = RLIM_SAVED_MAX;
|
|
|
|
setrlimit(RLIMIT_NOFILE, &rl);
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
fNodeMonitorCount = DEFAULT_MON_NUM;
|
2011-03-12 03:53:30 +03:00
|
|
|
|
|
|
|
gLocalizedNamePreferred
|
|
|
|
= BLocaleRoster::Default()->IsFilesystemTranslationPreferred();
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
#ifdef CHECK_OPEN_MODEL_LEAKS
|
|
|
|
InitOpenModelDumping();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
InitIconPreloader();
|
|
|
|
|
|
|
|
#ifdef LEAK_CHECKING
|
|
|
|
SetNewLeakChecking(true);
|
|
|
|
SetMallocLeakChecking(true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//This is how often it should update the free space bar on the volume icons
|
|
|
|
SetPulseRate(1000000);
|
2010-01-31 03:25:10 +03:00
|
|
|
|
|
|
|
gLaunchLooper = new LaunchLooper();
|
|
|
|
gLaunchLooper->Run();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TTracker::~TTracker()
|
|
|
|
{
|
2010-01-31 03:25:10 +03:00
|
|
|
gLaunchLooper->Lock();
|
|
|
|
gLaunchLooper->Quit();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TTracker::QuitRequested()
|
|
|
|
{
|
|
|
|
// don't allow user quitting
|
2009-03-29 12:36:55 +04:00
|
|
|
if (CurrentMessage() && CurrentMessage()->FindBool("shortcut")) {
|
|
|
|
// but allow quitting to hide fSettingsWindow
|
|
|
|
int32 index = 0;
|
2012-07-28 03:07:09 +04:00
|
|
|
BWindow* window = NULL;
|
2009-03-29 12:36:55 +04:00
|
|
|
while ((window = WindowAt(index++)) != NULL) {
|
|
|
|
if (window == fSettingsWindow) {
|
|
|
|
if (fSettingsWindow->Lock()) {
|
|
|
|
if (!fSettingsWindow->IsHidden()
|
|
|
|
&& fSettingsWindow->IsActive())
|
|
|
|
fSettingsWindow->Hide();
|
|
|
|
fSettingsWindow->Unlock();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
return false;
|
2009-03-29 12:36:55 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
gStatusWindow->AttemptToQuit();
|
|
|
|
// try quitting the copy/move/empty trash threads
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
BMessage message;
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
// save open windows in a message inside an attribute of the desktop
|
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = dynamic_cast<BContainerWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(i));
|
|
|
|
|
2008-10-22 13:02:17 +04:00
|
|
|
if (window && window->Lock()) {
|
|
|
|
if (window->TargetModel()
|
|
|
|
&& !window->PoseView()->IsDesktopWindow()) {
|
|
|
|
if (window->TargetModel()->IsRoot())
|
|
|
|
message.AddBool("open_disks_window", true);
|
|
|
|
else {
|
|
|
|
BEntry entry;
|
|
|
|
BPath path;
|
2012-07-28 03:07:09 +04:00
|
|
|
const entry_ref* ref = window->TargetModel()->EntryRef();
|
2008-10-22 13:02:17 +04:00
|
|
|
if (entry.SetTo(ref) == B_OK && entry.GetPath(&path) == B_OK) {
|
|
|
|
int8 flags = window->IsMinimized() ? kOpenWindowMinimized : kOpenWindowNoFlags;
|
|
|
|
uint32 deviceFlags = GetVolumeFlags(window->TargetModel());
|
|
|
|
|
|
|
|
// save state for every window which is
|
|
|
|
// a) already open on another workspace
|
|
|
|
// b) on a volume not capable of writing attributes
|
|
|
|
if (window != FindContainerWindow(ref)
|
|
|
|
|| (deviceFlags & (B_FS_HAS_ATTR | B_FS_IS_READONLY)) != B_FS_HAS_ATTR) {
|
|
|
|
BMessage stateMessage;
|
|
|
|
window->SaveState(stateMessage);
|
|
|
|
window->SetSaveStateEnabled(false);
|
|
|
|
// This is to prevent its state to be saved to the node when closed.
|
|
|
|
message.AddMessage("window state", &stateMessage);
|
|
|
|
flags |= kOpenWindowHasState;
|
|
|
|
}
|
2012-07-28 03:07:09 +04:00
|
|
|
const char* target;
|
2008-10-22 13:02:17 +04:00
|
|
|
bool pathAlreadyExists = false;
|
|
|
|
for (int32 index = 0;message.FindString("paths", index, &target) == B_OK;index++) {
|
|
|
|
if (!strcmp(target,path.Path())) {
|
|
|
|
pathAlreadyExists = true;
|
|
|
|
break;
|
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
2008-10-22 13:02:17 +04:00
|
|
|
if (!pathAlreadyExists)
|
|
|
|
message.AddString("paths", path.Path());
|
|
|
|
message.AddInt8(path.Path(), flags);
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
}
|
|
|
|
window->Unlock();
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lock.Unlock();
|
|
|
|
|
|
|
|
// write windows to open on disk
|
|
|
|
BDirectory deskDir;
|
2010-01-15 08:12:45 +03:00
|
|
|
if (!BootedInSafeMode() && FSGetDeskDir(&deskDir) == B_OK) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// if message is empty, delete the corresponding attribute
|
|
|
|
if (message.CountNames(B_ANY_TYPE)) {
|
|
|
|
size_t size = (size_t)message.FlattenedSize();
|
2012-07-28 03:07:09 +04:00
|
|
|
char* buffer = new char[size];
|
2005-05-23 04:58:42 +04:00
|
|
|
message.Flatten(buffer, (ssize_t)size);
|
|
|
|
deskDir.WriteAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer, size);
|
|
|
|
delete [] buffer;
|
|
|
|
} else
|
|
|
|
deskDir.RemoveAttr(kAttrOpenWindows);
|
|
|
|
}
|
|
|
|
|
2008-09-25 18:36:29 +04:00
|
|
|
for (int32 count = 0; count < 50; count++) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// wait 5 seconds for the copiing/moving to quit
|
|
|
|
if (gStatusWindow->AttemptToQuit())
|
|
|
|
break;
|
|
|
|
|
|
|
|
snooze(100000);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _inherited::QuitRequested();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TTracker::Quit()
|
|
|
|
{
|
|
|
|
TrackerSettings().SaveSettings(false);
|
|
|
|
|
|
|
|
fClipboardRefsWatcher->Lock();
|
|
|
|
fClipboardRefsWatcher->Quit();
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
fTrashWatcher->Lock();
|
|
|
|
fTrashWatcher->Quit();
|
|
|
|
|
|
|
|
WellKnowEntryList::Quit();
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
delete gPreloader;
|
|
|
|
delete fTaskLoop;
|
|
|
|
delete IconCache::sIconCache;
|
|
|
|
|
|
|
|
_inherited::Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::MessageReceived(BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
if (HandleScriptingMessage(message))
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (message->what) {
|
|
|
|
case kGetInfo:
|
|
|
|
OpenInfoWindows(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kMoveToTrash:
|
|
|
|
MoveRefsToTrash(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kCloseWindowAndChildren:
|
|
|
|
{
|
2012-07-28 03:07:09 +04:00
|
|
|
const node_ref* itemNode;
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 bytes;
|
|
|
|
message->FindData("node_ref", B_RAW_TYPE,
|
2012-07-28 03:07:09 +04:00
|
|
|
(const void**)&itemNode, &bytes);
|
2005-05-23 04:58:42 +04:00
|
|
|
CloseWindowAndChildren(itemNode);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
case kCloseAllWindows:
|
|
|
|
CloseAllWindows();
|
|
|
|
break;
|
|
|
|
|
2009-04-16 23:32:11 +04:00
|
|
|
case kCloseAllInWorkspace:
|
|
|
|
CloseAllInWorkspace();
|
|
|
|
break;
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
case kFindButton:
|
|
|
|
(new FindWindow())->Show();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kEditQuery:
|
|
|
|
EditQueries(message);
|
|
|
|
break;
|
|
|
|
|
2007-07-19 16:52:50 +04:00
|
|
|
case kShowSplash:
|
|
|
|
run_be_about();
|
|
|
|
break;
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
case kAddPrinter:
|
|
|
|
// show the addprinter window
|
|
|
|
run_add_printer_panel();
|
|
|
|
break;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
case kMakeActivePrinter:
|
|
|
|
// get the current selection
|
|
|
|
SetDefaultPrinter(message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef MOUNT_MENU_IN_DESKBAR
|
|
|
|
|
|
|
|
case 'gmtv':
|
2009-10-12 18:52:17 +04:00
|
|
|
{
|
|
|
|
// Someone (probably the deskbar) has requested a list of
|
|
|
|
// mountable volumes.
|
|
|
|
BMessage reply;
|
|
|
|
AutoMounterLoop()->EachMountableItemAndFloppy(&AddMountableItemToMessage,
|
|
|
|
&reply);
|
|
|
|
message->SendReply(&reply);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-10-12 18:52:17 +04:00
|
|
|
case kUnmountVolume:
|
|
|
|
// When the user attempts to unmount a volume from the mount
|
|
|
|
// context menu, this is where the message gets received.
|
|
|
|
// Save pose locations and forward this to the automounter
|
|
|
|
SaveAllPoseLocations();
|
|
|
|
// Fall through...
|
2005-05-23 04:58:42 +04:00
|
|
|
case kMountVolume:
|
|
|
|
case kMountAllNow:
|
2009-10-12 18:52:17 +04:00
|
|
|
MountServer().SendMessage(message);
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
|
|
|
|
2009-10-12 18:52:17 +04:00
|
|
|
case kRunAutomounterSettings:
|
|
|
|
AutomountSettingsDialog::RunAutomountSettings(MountServer());
|
|
|
|
break;
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
case kRestoreBackgroundImage:
|
2009-10-12 18:52:17 +04:00
|
|
|
{
|
2012-07-28 03:07:09 +04:00
|
|
|
BDeskWindow* desktop = GetDeskWindow();
|
2009-10-12 18:52:17 +04:00
|
|
|
AutoLock<BWindow> lock(desktop);
|
|
|
|
desktop->UpdateDesktopBackgroundImages();
|
2005-05-23 04:58:42 +04:00
|
|
|
break;
|
2009-10-12 18:52:17 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
case kShowSettingsWindow:
|
|
|
|
ShowSettingsWindow();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kFavoriteCountChangedExternally:
|
|
|
|
SendNotices(kFavoriteCountChangedExternally, message);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kStartWatchClipboardRefs:
|
|
|
|
{
|
|
|
|
BMessenger messenger;
|
|
|
|
message->FindMessenger("target", &messenger);
|
|
|
|
if (messenger.IsValid())
|
|
|
|
fClipboardRefsWatcher->AddToNotifyList(messenger);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kStopWatchClipboardRefs:
|
|
|
|
{
|
|
|
|
BMessenger messenger;
|
|
|
|
message->FindMessenger("target", &messenger);
|
|
|
|
if (messenger.IsValid())
|
|
|
|
fClipboardRefsWatcher->RemoveFromNotifyList(messenger);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kFSClipboardChanges:
|
|
|
|
fClipboardRefsWatcher->UpdatePoseViews(message);
|
|
|
|
break;
|
|
|
|
|
2007-06-19 13:33:29 +04:00
|
|
|
case kShowVolumeSpaceBar:
|
2009-10-12 18:52:17 +04:00
|
|
|
case kSpaceBarColorChanged:
|
2007-06-19 13:33:29 +04:00
|
|
|
gPeriodicUpdatePoses.DoPeriodicUpdate(true);
|
|
|
|
break;
|
|
|
|
|
2011-03-12 03:53:30 +03:00
|
|
|
case B_LOCALE_CHANGED:
|
|
|
|
{
|
|
|
|
BLocaleRoster::Default()->Refresh();
|
|
|
|
bool localize;
|
|
|
|
if (message->FindBool("filesys", &localize) == B_OK)
|
|
|
|
gLocalizedNamePreferred = localize;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
default:
|
|
|
|
_inherited::MessageReceived(message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TTracker::Pulse()
|
|
|
|
{
|
|
|
|
if (!TrackerSettings().ShowVolumeSpaceBar())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update the volume icon's free space bars
|
2007-06-19 13:33:29 +04:00
|
|
|
gPeriodicUpdatePoses.DoPeriodicUpdate(false);
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::SetDefaultPrinter(const BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
// get the first item selected
|
|
|
|
int32 count = 0;
|
|
|
|
uint32 type = 0;
|
|
|
|
message->GetInfo("refs", &type, &count);
|
|
|
|
|
|
|
|
if (count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// will make the first item the default printer, disregards any other files
|
|
|
|
entry_ref ref;
|
|
|
|
ASSERT(message->FindRef("refs", 0, &ref) == B_OK);
|
|
|
|
if (message->FindRef("refs", 0, &ref) != B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if B_BEOS_VERSION_DANO
|
|
|
|
set_default_printer(ref.name);
|
|
|
|
#else
|
|
|
|
// create a message for the print server
|
|
|
|
BMessenger messenger("application/x-vnd.Be-PSRV", -1);
|
|
|
|
if (!messenger.IsValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// send the selection to the print server
|
|
|
|
BMessage makeActiveMessage(PSV_MAKE_PRINTER_ACTIVE_QUIETLY);
|
|
|
|
makeActiveMessage.AddString("printer", ref.name);
|
|
|
|
|
|
|
|
BMessage reply;
|
|
|
|
messenger.SendMessage(&makeActiveMessage, &reply);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::MoveRefsToTrash(const BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
int32 count;
|
|
|
|
uint32 type;
|
|
|
|
message->GetInfo("refs", &type, &count);
|
|
|
|
|
|
|
|
if (count <= 0)
|
|
|
|
return;
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BObjectList<entry_ref>* srcList = new BObjectList<entry_ref>(count, true);
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
|
|
|
|
entry_ref ref;
|
|
|
|
ASSERT(message->FindRef("refs", index, &ref) == B_OK);
|
|
|
|
if (message->FindRef("refs", index, &ref) != B_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = FindParentContainerWindow(&ref);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (window)
|
|
|
|
// if we have a window open for this entry, ask the pose to
|
|
|
|
// delete it, this will select the next entry
|
|
|
|
window->PoseView()->MoveEntryToTrash(&ref);
|
|
|
|
else
|
|
|
|
// add all others to a list that gets deleted separately
|
|
|
|
srcList->AddItem(new entry_ref(ref));
|
|
|
|
}
|
|
|
|
|
2012-01-06 02:52:21 +04:00
|
|
|
// async move to trash
|
|
|
|
FSMoveToTrash(srcList);
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <class T, class FT>
|
|
|
|
class EntryAndNodeDoSoonWithMessageFunctor : public FunctionObjectWithResult<bool> {
|
|
|
|
public:
|
2012-07-28 03:07:09 +04:00
|
|
|
EntryAndNodeDoSoonWithMessageFunctor(FT func, T* target, const entry_ref* child,
|
|
|
|
const node_ref* parent, const BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
: fFunc(func),
|
|
|
|
fTarget(target),
|
|
|
|
fNode(*parent),
|
|
|
|
fEntry(*child)
|
|
|
|
{
|
|
|
|
fSendMessage = (message != NULL);
|
|
|
|
if (message)
|
|
|
|
fMessage = *message;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~EntryAndNodeDoSoonWithMessageFunctor() {}
|
|
|
|
virtual void operator()()
|
|
|
|
{ result = (fTarget->*fFunc)(&fEntry, &fNode, fSendMessage ? &fMessage : NULL); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FT fFunc;
|
2012-07-28 03:07:09 +04:00
|
|
|
T* fTarget;
|
2005-05-23 04:58:42 +04:00
|
|
|
node_ref fNode;
|
|
|
|
entry_ref fEntry;
|
|
|
|
BMessage fMessage;
|
|
|
|
bool fSendMessage;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::LaunchAndCloseParentIfOK(const entry_ref* launchThis,
|
|
|
|
const node_ref* closeThis, const BMessage* messageToBundle)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
BMessage refsReceived(B_REFS_RECEIVED);
|
|
|
|
if (messageToBundle) {
|
|
|
|
refsReceived = *messageToBundle;
|
|
|
|
refsReceived.what = B_REFS_RECEIVED;
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
refsReceived.AddRef("refs", launchThis);
|
2005-05-23 04:58:42 +04:00
|
|
|
// synchronous launch, we are already in our own thread
|
|
|
|
if (TrackerLaunch(&refsReceived, false) == B_OK) {
|
|
|
|
// if launched fine, close parent window in a bit
|
|
|
|
fTaskLoop->RunLater(NewMemberFunctionObject(&TTracker::CloseParent, this, *closeThis),
|
|
|
|
1000000);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::OpenRef(const entry_ref* ref, const node_ref* nodeToClose,
|
|
|
|
const node_ref* nodeToSelect, OpenSelector selector,
|
|
|
|
const BMessage* messageToBundle)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
2012-07-28 03:07:09 +04:00
|
|
|
Model* model = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
BEntry entry(ref, true);
|
|
|
|
status_t result = entry.InitCheck();
|
|
|
|
|
|
|
|
bool brokenLinkWithSpecificHandler = false;
|
|
|
|
BString brokenLinkPreferredApp;
|
|
|
|
|
|
|
|
if (result != B_OK) {
|
|
|
|
model = new Model(ref, false);
|
|
|
|
if (model->IsSymLink() && !model->LinkTo()) {
|
|
|
|
model->GetPreferredAppForBrokenSymLink(brokenLinkPreferredApp);
|
|
|
|
if (brokenLinkPreferredApp.Length() && brokenLinkPreferredApp != kTrackerSignature)
|
|
|
|
brokenLinkWithSpecificHandler = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!brokenLinkWithSpecificHandler) {
|
|
|
|
delete model;
|
2010-07-13 16:39:53 +04:00
|
|
|
BAlert* alert = new BAlert("",
|
|
|
|
B_TRANSLATE("There was an error resolving the link."),
|
|
|
|
B_TRANSLATE("Cancel"), 0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
2009-04-06 03:47:58 +04:00
|
|
|
alert->SetShortcut(0, B_ESCAPE);
|
|
|
|
alert->Go();
|
2005-05-23 04:58:42 +04:00
|
|
|
return result;
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
} else
|
2005-05-23 04:58:42 +04:00
|
|
|
model = new Model(&entry);
|
|
|
|
|
|
|
|
result = model->InitCheck();
|
|
|
|
if (result != B_OK) {
|
|
|
|
delete model;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool openAsContainer = model->IsContainer();
|
|
|
|
|
|
|
|
if (openAsContainer && selector != kOpenWith) {
|
|
|
|
// if folder or query has a preferred handler and it's not the
|
|
|
|
// Tracker, open it by sending refs to the handling app
|
|
|
|
|
|
|
|
// if we are responding to the final open of OpenWith, just
|
|
|
|
// skip this and proceed to opening the container with Tracker
|
|
|
|
model->OpenNode();
|
|
|
|
BNodeInfo nodeInfo(model->Node());
|
|
|
|
char preferredApp[B_MIME_TYPE_LENGTH];
|
|
|
|
if (nodeInfo.GetPreferredApp(preferredApp) == B_OK
|
|
|
|
&& strcasecmp(preferredApp, kTrackerSignature) != 0)
|
|
|
|
openAsContainer = false;
|
|
|
|
model->CloseNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openAsContainer || selector == kRunOpenWithWindow) {
|
|
|
|
// special case opening plain folders, queries or using open with
|
2006-05-27 01:48:53 +04:00
|
|
|
OpenContainerWindow(model, 0, selector, kRestoreDecor); // window adopts model
|
2005-05-23 04:58:42 +04:00
|
|
|
if (nodeToClose)
|
|
|
|
CloseParentWaitingForChildSoon(ref, nodeToClose);
|
|
|
|
} else if (model->IsQueryTemplate()) {
|
|
|
|
// query template - open new find window
|
|
|
|
(new FindWindow(model->EntryRef()))->Show();
|
2012-01-05 04:49:27 +04:00
|
|
|
|
|
|
|
delete model;
|
2005-05-23 04:58:42 +04:00
|
|
|
if (nodeToClose)
|
|
|
|
CloseParentWaitingForChildSoon(ref, nodeToClose);
|
|
|
|
} else {
|
|
|
|
delete model;
|
|
|
|
// run Launch in a separate thread
|
|
|
|
// and close parent if successfull
|
|
|
|
if (nodeToClose)
|
|
|
|
Thread::Launch(new EntryAndNodeDoSoonWithMessageFunctor<TTracker,
|
2012-07-28 03:07:09 +04:00
|
|
|
bool (TTracker::*)(const entry_ref*, const node_ref*,
|
|
|
|
const BMessage*)>(&TTracker::LaunchAndCloseParentIfOK, this,
|
2005-05-23 04:58:42 +04:00
|
|
|
ref, nodeToClose, messageToBundle));
|
|
|
|
else {
|
|
|
|
BMessage refsReceived(B_REFS_RECEIVED);
|
|
|
|
if (messageToBundle) {
|
|
|
|
refsReceived = *messageToBundle;
|
|
|
|
refsReceived.what = B_REFS_RECEIVED;
|
|
|
|
}
|
|
|
|
refsReceived.AddRef("refs", ref);
|
|
|
|
if (brokenLinkWithSpecificHandler)
|
|
|
|
// This cruft is to support a hacky workaround for double-clicking
|
|
|
|
// broken refs for cifs; should get fixed in R5
|
|
|
|
LaunchBrokenLink(brokenLinkPreferredApp.String(), &refsReceived);
|
|
|
|
else
|
|
|
|
TrackerLaunch(&refsReceived, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nodeToSelect)
|
|
|
|
SelectChildInParentSoon(ref, nodeToSelect);
|
|
|
|
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::RefsReceived(BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
OpenSelector selector = kOpen;
|
|
|
|
if (message->HasInt32("launchUsingSelector"))
|
|
|
|
selector = kRunOpenWithWindow;
|
|
|
|
|
|
|
|
entry_ref handlingApp;
|
|
|
|
if (message->FindRef("handler", &handlingApp) == B_OK)
|
|
|
|
selector = kOpenWith;
|
|
|
|
|
|
|
|
int32 count;
|
|
|
|
uint32 type;
|
|
|
|
message->GetInfo("refs", &type, &count);
|
|
|
|
|
|
|
|
switch (selector) {
|
|
|
|
case kRunOpenWithWindow:
|
|
|
|
OpenContainerWindow(0, message, selector);
|
|
|
|
// window adopts model
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kOpenWith:
|
|
|
|
{
|
|
|
|
// Open With resulted in passing refs and a handler, open the files
|
|
|
|
// with the handling app
|
|
|
|
message->RemoveName("handler");
|
|
|
|
|
|
|
|
// have to find out if handling app is the Tracker
|
|
|
|
// if it is, just pass it to the active Tracker, no matter which Tracker
|
|
|
|
// was chosen to handle the refs
|
|
|
|
char signature[B_MIME_TYPE_LENGTH];
|
|
|
|
signature[0] = '\0';
|
|
|
|
{
|
|
|
|
BFile handlingNode(&handlingApp, O_RDONLY);
|
|
|
|
BAppFileInfo appInfo(&handlingNode);
|
|
|
|
appInfo.GetSignature(signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcasecmp(signature, kTrackerSignature) != 0) {
|
|
|
|
// handling app not Tracker, pass entries to the apps RefsReceived
|
|
|
|
TrackerLaunch(&handlingApp, message, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall thru, opening refs by the Tracker, as if they were double clicked
|
|
|
|
}
|
|
|
|
|
|
|
|
case kOpen:
|
|
|
|
{
|
|
|
|
// copy over "Poses" messenger so that refs received recipients know
|
|
|
|
// where the open came from
|
2012-07-28 03:07:09 +04:00
|
|
|
BMessage* bundleThis = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
BMessenger messenger;
|
|
|
|
if (message->FindMessenger("TrackerViewToken", &messenger) == B_OK) {
|
|
|
|
bundleThis = new BMessage();
|
|
|
|
bundleThis->AddMessenger("TrackerViewToken", messenger);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
entry_ref ref;
|
|
|
|
message->FindRef("refs", index, &ref);
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
const node_ref* nodeToClose = NULL;
|
|
|
|
const node_ref* nodeToSelect = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
ssize_t numBytes;
|
|
|
|
|
|
|
|
message->FindData("nodeRefsToClose", B_RAW_TYPE, index,
|
2012-07-28 03:07:09 +04:00
|
|
|
(const void**)&nodeToClose, &numBytes);
|
2005-05-23 04:58:42 +04:00
|
|
|
message->FindData("nodeRefToSelect", B_RAW_TYPE, index,
|
2012-07-28 03:07:09 +04:00
|
|
|
(const void**)&nodeToSelect, &numBytes);
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
OpenRef(&ref, nodeToClose, nodeToSelect, selector, bundleThis);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete bundleThis;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::ArgvReceived(int32 argc, char** argv)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
2012-07-28 03:07:09 +04:00
|
|
|
BMessage* message = CurrentMessage();
|
|
|
|
const char* currentWorkingDirectoryPath = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
entry_ref ref;
|
|
|
|
|
|
|
|
if (message->FindString("cwd", ¤tWorkingDirectoryPath) == B_OK) {
|
|
|
|
BDirectory workingDirectory(currentWorkingDirectoryPath);
|
|
|
|
for (int32 index = 1; index < argc; index++) {
|
|
|
|
BEntry entry;
|
|
|
|
if (entry.SetTo(&workingDirectory, argv[index]) == B_OK
|
2009-06-14 14:57:09 +04:00
|
|
|
&& entry.GetRef(&ref) == B_OK)
|
2005-05-23 04:58:42 +04:00
|
|
|
OpenRef(&ref);
|
|
|
|
else if (get_ref_for_path(argv[index], &ref) == B_OK)
|
|
|
|
OpenRef(&ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::OpenContainerWindow(Model* model, BMessage* originalRefsList,
|
2005-05-23 04:58:42 +04:00
|
|
|
OpenSelector openSelector, uint32 openFlags, bool checkAlreadyOpen,
|
2012-07-28 03:07:09 +04:00
|
|
|
const BMessage* stateMessage)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
if (checkAlreadyOpen && openSelector != kRunOpenWithWindow)
|
|
|
|
// find out if window already open
|
|
|
|
window = FindContainerWindow(model->NodeRef());
|
|
|
|
|
|
|
|
bool someWindowActivated = false;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
|
|
|
uint32 workspace = (uint32)(1 << current_workspace());
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 windowCount = 0;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
while (window) {
|
|
|
|
// At least one window open, just pull to front
|
2009-06-14 14:57:09 +04:00
|
|
|
// make sure we don't jerk workspaces around
|
2005-05-23 04:58:42 +04:00
|
|
|
uint32 windowWorkspaces = window->Workspaces();
|
|
|
|
if (windowWorkspaces & workspace) {
|
|
|
|
window->Activate();
|
|
|
|
someWindowActivated = true;
|
|
|
|
}
|
|
|
|
window = FindContainerWindow(model->NodeRef(), ++windowCount);
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (someWindowActivated) {
|
|
|
|
delete model;
|
2009-06-14 14:57:09 +04:00
|
|
|
return;
|
2005-05-23 04:58:42 +04:00
|
|
|
} // If no window was actiated, (none in the current workspace
|
|
|
|
// we open a new one.
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (openSelector == kRunOpenWithWindow) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BMessage* refList = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
if (!originalRefsList) {
|
|
|
|
// when passing just a single model, stuff it's entry in a single
|
|
|
|
// element list anyway
|
|
|
|
ASSERT(model);
|
|
|
|
refList = new BMessage;
|
|
|
|
refList->AddRef("refs", model->EntryRef());
|
|
|
|
delete model;
|
|
|
|
model = NULL;
|
|
|
|
} else
|
|
|
|
// clone the message, window adopts it for it's own use
|
|
|
|
refList = new BMessage(*originalRefsList);
|
|
|
|
window = new OpenWithContainerWindow(refList, &fWindowList);
|
|
|
|
} else if (model->IsRoot()) {
|
|
|
|
// window will adopt the model
|
|
|
|
window = new BVolumeWindow(&fWindowList, openFlags);
|
|
|
|
} else if (model->IsQuery()) {
|
|
|
|
// window will adopt the model
|
|
|
|
window = new BQueryContainerWindow(&fWindowList, openFlags);
|
|
|
|
} else
|
|
|
|
// window will adopt the model
|
|
|
|
window = new BContainerWindow(&fWindowList, openFlags);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (model)
|
|
|
|
window->CreatePoseView(model);
|
|
|
|
|
|
|
|
BMessage restoreStateMessage(kRestoreState);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (stateMessage)
|
|
|
|
restoreStateMessage.AddMessage("state", stateMessage);
|
|
|
|
|
|
|
|
window->PostMessage(&restoreStateMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::EditQueries(const BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
bool editOnlyIfTemplate;
|
|
|
|
if (message->FindBool("editQueryOnPose", &editOnlyIfTemplate) != B_OK)
|
|
|
|
editOnlyIfTemplate = false;
|
|
|
|
|
|
|
|
type_code type;
|
|
|
|
int32 count;
|
|
|
|
message->GetInfo("refs", &type, &count);
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
entry_ref ref;
|
|
|
|
message->FindRef("refs", index, &ref);
|
|
|
|
BEntry entry(&ref, true);
|
2009-06-14 14:57:09 +04:00
|
|
|
if (entry.InitCheck() == B_OK && entry.Exists())
|
2005-05-23 04:58:42 +04:00
|
|
|
(new FindWindow(&ref, editOnlyIfTemplate))->Show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::OpenInfoWindows(BMessage* message)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
type_code type;
|
|
|
|
int32 count;
|
|
|
|
message->GetInfo("refs", &type, &count);
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
entry_ref ref;
|
|
|
|
message->FindRef("refs", index, &ref);
|
|
|
|
BEntry entry;
|
|
|
|
if (entry.SetTo(&ref) == B_OK) {
|
2012-07-28 03:07:09 +04:00
|
|
|
Model* model = new Model(&entry);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (model->InitCheck() != B_OK) {
|
|
|
|
delete model;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2012-07-28 03:07:09 +04:00
|
|
|
BInfoWindow* wind = FindInfoWindow(model->NodeRef());
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
if (wind) {
|
|
|
|
wind->Activate();
|
|
|
|
delete model;
|
|
|
|
} else {
|
|
|
|
wind = new BInfoWindow(model, index, &fWindowList);
|
|
|
|
wind->PostMessage(kRestoreState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BDeskWindow*
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::GetDeskWindow() const
|
|
|
|
{
|
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BDeskWindow* window = dynamic_cast<BDeskWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
TRESPASS();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow*
|
|
|
|
TTracker::FindContainerWindow(const node_ref* node, int32 number) const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
ASSERT(fWindowList.IsLocked());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
|
|
|
|
int32 windowsFound = 0;
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = dynamic_cast<BContainerWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (window && window->IsShowing(node) && number == windowsFound++)
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow*
|
|
|
|
TTracker::FindContainerWindow(const entry_ref* entry, int32 number) const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
ASSERT(fWindowList.IsLocked());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
|
|
|
|
int32 windowsFound = 0;
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = dynamic_cast<BContainerWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
|
|
|
|
|
|
|
if (window && window->IsShowing(entry) && number == windowsFound++)
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::EntryHasWindowOpen(const entry_ref* entry)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
return FindContainerWindow(entry) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow*
|
|
|
|
TTracker::FindParentContainerWindow(const entry_ref* ref) const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
BEntry entry(ref);
|
|
|
|
BEntry parent;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (entry.GetParent(&parent) != B_OK)
|
|
|
|
return NULL;
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
entry_ref parentRef;
|
|
|
|
parent.GetRef(&parentRef);
|
|
|
|
|
|
|
|
ASSERT(fWindowList.IsLocked());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = dynamic_cast<BContainerWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
|
|
|
if (window && window->IsShowing(&parentRef))
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BInfoWindow*
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::FindInfoWindow(const node_ref* node) const
|
|
|
|
{
|
|
|
|
ASSERT(fWindowList.IsLocked());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BInfoWindow* window = dynamic_cast<BInfoWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
|
|
|
if (window && window->IsShowing(node))
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::QueryActiveForDevice(dev_t device)
|
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
int32 count = fWindowList.CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BQueryContainerWindow* window
|
|
|
|
= dynamic_cast<BQueryContainerWindow*>(fWindowList.ItemAt(index));
|
2005-05-23 04:58:42 +04:00
|
|
|
if (window) {
|
|
|
|
AutoLock<BWindow> lock(window);
|
|
|
|
if (window->ActiveOnDevice(device))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::CloseActiveQueryWindows(dev_t device)
|
|
|
|
{
|
|
|
|
// used when trying to unmount a volume - an active query would prevent that from
|
|
|
|
// happening
|
|
|
|
bool closed = false;
|
|
|
|
AutoLock<WindowList> lock(fWindowList);
|
|
|
|
for (int32 index = fWindowList.CountItems(); index >= 0; index--) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BQueryContainerWindow* window
|
|
|
|
= dynamic_cast<BQueryContainerWindow*>(fWindowList.ItemAt(index));
|
2005-05-23 04:58:42 +04:00
|
|
|
if (window) {
|
|
|
|
AutoLock<BWindow> lock(window);
|
|
|
|
if (window->ActiveOnDevice(device)) {
|
|
|
|
window->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
closed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lock.Unlock();
|
|
|
|
if (closed)
|
|
|
|
for (int32 timeout = 30; timeout; timeout--) {
|
|
|
|
// wait a bit for windows to fully close
|
|
|
|
if (!QueryActiveForDevice(device))
|
|
|
|
return;
|
|
|
|
snooze(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TTracker::SaveAllPoseLocations()
|
|
|
|
{
|
|
|
|
int32 numWindows = fWindowList.CountItems();
|
|
|
|
for (int32 windowIndex = 0; windowIndex < numWindows; windowIndex++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window
|
|
|
|
= dynamic_cast<BContainerWindow*>(fWindowList.ItemAt(windowIndex));
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
if (window) {
|
|
|
|
AutoLock<BWindow> lock(window);
|
2012-07-28 03:07:09 +04:00
|
|
|
BDeskWindow* deskWindow = dynamic_cast<BDeskWindow*>(window);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
|
|
|
if (deskWindow)
|
2005-05-23 04:58:42 +04:00
|
|
|
deskWindow->SaveDesktopPoseLocations();
|
|
|
|
else
|
|
|
|
window->PoseView()->SavePoseLocations();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::CloseWindowAndChildren(const node_ref* node)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
BDirectory dir(node);
|
|
|
|
if (dir.InitCheck() != B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
BObjectList<BContainerWindow> closeList;
|
|
|
|
|
|
|
|
// make a list of all windows to be closed
|
|
|
|
// count from end to beginning so we can remove items safely
|
|
|
|
for (int32 index = fWindowList.CountItems() - 1; index >= 0; index--) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = dynamic_cast<BContainerWindow*>
|
2005-05-23 04:58:42 +04:00
|
|
|
(fWindowList.ItemAt(index));
|
|
|
|
if (window && window->TargetModel()) {
|
|
|
|
BEntry wind_entry;
|
|
|
|
wind_entry.SetTo(window->TargetModel()->EntryRef());
|
|
|
|
|
|
|
|
if ((*window->TargetModel()->NodeRef() == *node)
|
|
|
|
|| dir.Contains(&wind_entry)) {
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
// ToDo:
|
|
|
|
// get rid of the Remove here, BContainerWindow::Quit does it
|
|
|
|
fWindowList.RemoveItemAt(index);
|
|
|
|
closeList.AddItem(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now really close the windows
|
|
|
|
int32 numItems = closeList.CountItems();
|
|
|
|
for (int32 index = 0; index < numItems; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = closeList.ItemAt(index);
|
2005-05-23 04:58:42 +04:00
|
|
|
window->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 23:32:11 +04:00
|
|
|
void
|
|
|
|
TTracker::CloseAllInWorkspace()
|
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
|
|
|
|
int32 currentWorkspace = 1 << current_workspace();
|
|
|
|
// count from end to beginning so we can remove items safely
|
|
|
|
for (int32 index = fWindowList.CountItems() - 1; index >= 0; index--) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BWindow* window = fWindowList.ItemAt(index);
|
2009-04-16 23:32:11 +04:00
|
|
|
if (window->Workspaces() & currentWorkspace)
|
|
|
|
// avoid the desktop
|
2012-07-28 03:07:09 +04:00
|
|
|
if (!dynamic_cast<BDeskWindow*>(window)
|
|
|
|
&& !dynamic_cast<BStatusWindow*>(window))
|
2009-04-16 23:32:11 +04:00
|
|
|
window->PostMessage(B_QUIT_REQUESTED);
|
2009-06-14 14:57:09 +04:00
|
|
|
}
|
|
|
|
}
|
2009-04-16 23:32:11 +04:00
|
|
|
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
void
|
|
|
|
TTracker::CloseAllWindows()
|
|
|
|
{
|
|
|
|
// this is a response to the DeskBar sending us a B_QUIT, when it really
|
|
|
|
// means to say close all your windows. It might be better to have it
|
|
|
|
// send a kCloseAllWindows message and have windowless apps stay running,
|
|
|
|
// which is what we will do for the Tracker
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
|
|
|
|
int32 count = CountWindows();
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BWindow* window = WindowAt(index);
|
2005-05-23 04:58:42 +04:00
|
|
|
// avoid the desktop
|
2012-07-28 03:07:09 +04:00
|
|
|
if (!dynamic_cast<BDeskWindow*>(window)
|
|
|
|
&& !dynamic_cast<BStatusWindow*>(window))
|
2005-05-23 04:58:42 +04:00
|
|
|
window->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
}
|
|
|
|
// count from end to beginning so we can remove items safely
|
|
|
|
for (int32 index = fWindowList.CountItems() - 1; index >= 0; index--) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BWindow* window = fWindowList.ItemAt(index);
|
|
|
|
if (!dynamic_cast<BDeskWindow*>(window)
|
|
|
|
&& !dynamic_cast<BStatusWindow*>(window))
|
2005-05-23 04:58:42 +04:00
|
|
|
// ToDo:
|
|
|
|
// get rid of the Remove here, BContainerWindow::Quit does it
|
|
|
|
fWindowList.RemoveItemAt(index);
|
2009-06-14 14:57:09 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-19 16:52:50 +04:00
|
|
|
void
|
|
|
|
TTracker::_OpenPreviouslyOpenedWindows(const char* pathFilter)
|
|
|
|
{
|
|
|
|
size_t filterLength = 0;
|
|
|
|
if (pathFilter != NULL)
|
|
|
|
filterLength = strlen(pathFilter);
|
|
|
|
|
|
|
|
BDirectory deskDir;
|
|
|
|
attr_info attrInfo;
|
2010-01-15 08:12:45 +03:00
|
|
|
if (FSGetDeskDir(&deskDir) != B_OK
|
2007-07-19 16:52:50 +04:00
|
|
|
|| deskDir.GetAttrInfo(kAttrOpenWindows, &attrInfo) != B_OK)
|
|
|
|
return;
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
char* buffer = (char*)malloc((size_t)attrInfo.size);
|
2007-07-19 16:52:50 +04:00
|
|
|
BMessage message;
|
|
|
|
if (deskDir.ReadAttr(kAttrOpenWindows, B_MESSAGE_TYPE, 0, buffer,
|
|
|
|
(size_t)attrInfo.size) != attrInfo.size
|
|
|
|
|| message.Unflatten(buffer) != B_OK) {
|
|
|
|
free(buffer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
node_ref nodeRef;
|
|
|
|
deskDir.GetNodeRef(&nodeRef);
|
|
|
|
|
|
|
|
int32 stateMessageCounter = 0;
|
2012-07-28 03:07:09 +04:00
|
|
|
const char* path;
|
2007-07-19 16:52:50 +04:00
|
|
|
for (int32 i = 0; message.FindString("paths", i, &path) == B_OK; i++) {
|
|
|
|
if (strncmp(path, pathFilter, filterLength))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BEntry entry(path, true);
|
|
|
|
if (entry.InitCheck() != B_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int8 flags = 0;
|
|
|
|
for (int32 j = 0; message.FindInt8(path, j, &flags) == B_OK; j++) {
|
2012-07-28 03:07:09 +04:00
|
|
|
Model* model = new Model(&entry);
|
2007-07-19 16:52:50 +04:00
|
|
|
if (model->InitCheck() == B_OK && model->IsContainer()) {
|
|
|
|
BMessage state;
|
|
|
|
bool restoreStateFromMessage = false;
|
|
|
|
if ((flags & kOpenWindowHasState) != 0
|
|
|
|
&& message.FindMessage("window state", stateMessageCounter++,
|
|
|
|
&state) == B_OK)
|
|
|
|
restoreStateFromMessage = true;
|
|
|
|
|
|
|
|
if (restoreStateFromMessage) {
|
|
|
|
OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace
|
|
|
|
| (flags & kOpenWindowMinimized ? kIsHidden : 0U)
|
|
|
|
| kRestoreDecor, false, &state);
|
|
|
|
} else {
|
|
|
|
OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace
|
|
|
|
| (flags & kOpenWindowMinimized ? kIsHidden : 0U)
|
|
|
|
| kRestoreDecor);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
delete model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open disks window if needed
|
|
|
|
|
|
|
|
if (pathFilter == NULL && TrackerSettings().ShowDisksIcon()
|
|
|
|
&& message.HasBool("open_disks_window")) {
|
|
|
|
BEntry entry("/");
|
|
|
|
Model* model = new Model(&entry);
|
|
|
|
if (model->InitCheck() == B_OK)
|
|
|
|
OpenContainerWindow(model, 0, kOpen, kRestoreWorkspace);
|
|
|
|
else
|
|
|
|
delete model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
void
|
|
|
|
TTracker::ReadyToRun()
|
|
|
|
{
|
|
|
|
gStatusWindow = new BStatusWindow();
|
|
|
|
InitMimeTypes();
|
|
|
|
InstallDefaultTemplates();
|
|
|
|
InstallIndices();
|
2007-08-22 19:01:38 +04:00
|
|
|
InstallTemporaryBackgroundImages();
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
fTrashWatcher = new BTrashWatcher();
|
|
|
|
fTrashWatcher->Run();
|
|
|
|
|
|
|
|
fClipboardRefsWatcher = new BClipboardRefsWatcher();
|
|
|
|
fClipboardRefsWatcher->Run();
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
fTaskLoop = new StandAloneTaskLoop(true);
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
// open desktop window
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* deskWindow = NULL;
|
2005-05-23 04:58:42 +04:00
|
|
|
BDirectory deskDir;
|
2010-01-15 08:12:45 +03:00
|
|
|
if (FSGetDeskDir(&deskDir) == B_OK) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// create desktop
|
|
|
|
BEntry entry;
|
|
|
|
deskDir.GetEntry(&entry);
|
2012-07-28 03:07:09 +04:00
|
|
|
Model* model = new Model(&entry, true);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (model->InitCheck() == B_OK) {
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
deskWindow = new BDeskWindow(&fWindowList);
|
|
|
|
AutoLock<BWindow> windowLock(deskWindow);
|
|
|
|
deskWindow->CreatePoseView(model);
|
|
|
|
deskWindow->Init();
|
|
|
|
|
2007-07-19 16:52:50 +04:00
|
|
|
if (TrackerSettings().ShowDisksIcon()) {
|
|
|
|
// create model for root of everything
|
|
|
|
BEntry entry("/");
|
|
|
|
Model model(&entry);
|
|
|
|
if (model.InitCheck() == B_OK) {
|
|
|
|
// add the root icon to desktop window
|
|
|
|
BMessage message;
|
|
|
|
message.what = B_NODE_MONITOR;
|
|
|
|
message.AddInt32("opcode", B_ENTRY_CREATED);
|
|
|
|
message.AddInt32("device", model.NodeRef()->device);
|
|
|
|
message.AddInt64("node", model.NodeRef()->node);
|
|
|
|
message.AddInt64("directory", model.EntryRef()->directory);
|
|
|
|
message.AddString("name", model.EntryRef()->name);
|
|
|
|
deskWindow->PostMessage(&message, deskWindow->PoseView());
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-19 16:52:50 +04:00
|
|
|
} else
|
|
|
|
delete model;
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// kick off building the mime type list for find panels, etc.
|
|
|
|
fMimeTypeList = new MimeTypeList();
|
|
|
|
|
2007-07-19 16:52:50 +04:00
|
|
|
if (!BootedInSafeMode()) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// kick of transient query killer
|
|
|
|
DeleteTransientQueriesTask::StartUpTransientQueryCleaner();
|
2009-10-12 18:52:17 +04:00
|
|
|
// the mount_server will have mounted the previous volumes already.
|
|
|
|
_OpenPreviouslyOpenedWindows();
|
2007-07-19 16:52:50 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
MimeTypeList*
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::MimeTypes() const
|
|
|
|
{
|
|
|
|
return fMimeTypeList;
|
2009-06-14 14:57:09 +04:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::SelectChildInParentSoon(const entry_ref* parent,
|
|
|
|
const node_ref* child)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
fTaskLoop->RunLater(NewMemberFunctionObjectWithResult
|
|
|
|
(&TTracker::SelectChildInParent, this, parent, child),
|
|
|
|
100000, 200000, 5000000);
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::CloseParentWaitingForChildSoon(const entry_ref* child,
|
|
|
|
const node_ref* parent)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
fTaskLoop->RunLater(NewMemberFunctionObjectWithResult
|
|
|
|
(&TTracker::CloseParentWaitingForChild, this, child, parent),
|
|
|
|
200000, 100000, 5000000);
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::SelectPoseAtLocationSoon(node_ref parent, BPoint pointInPose)
|
|
|
|
{
|
|
|
|
fTaskLoop->RunLater(NewMemberFunctionObject
|
|
|
|
(&TTracker::SelectPoseAtLocationInParent, this, parent, pointInPose),
|
|
|
|
100000);
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::SelectPoseAtLocationInParent(node_ref parent, BPoint pointInPose)
|
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* parentWindow = FindContainerWindow(&parent);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (parentWindow) {
|
|
|
|
AutoLock<BWindow> lock(parentWindow);
|
|
|
|
parentWindow->PoseView()->SelectPoseAtLocation(pointInPose);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::CloseParentWaitingForChild(const entry_ref* child,
|
|
|
|
const node_ref* parent)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* parentWindow = FindContainerWindow(parent);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (!parentWindow)
|
|
|
|
// parent window already closed, give up
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If child is a symbolic link, dereference it, so that
|
|
|
|
// FindContainerWindow will succeed.
|
|
|
|
BEntry entry(child, true);
|
|
|
|
entry_ref resolvedChild;
|
|
|
|
if (entry.GetRef(&resolvedChild) != B_OK)
|
|
|
|
resolvedChild = *child;
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = FindContainerWindow(&resolvedChild);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (window) {
|
|
|
|
AutoLock<BWindow> lock(window);
|
|
|
|
if (!window->IsHidden())
|
|
|
|
return CloseParentWindowCommon(parentWindow);
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
return false;
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
void
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::CloseParent(node_ref parent)
|
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
|
|
|
if (!lock)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CloseParentWindowCommon(FindContainerWindow(&parent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TTracker::ShowSettingsWindow()
|
|
|
|
{
|
|
|
|
if (!fSettingsWindow) {
|
|
|
|
fSettingsWindow = new TrackerSettingsWindow();
|
|
|
|
fSettingsWindow->Show();
|
|
|
|
} else {
|
|
|
|
if (fSettingsWindow->Lock()) {
|
|
|
|
if (fSettingsWindow->IsHidden())
|
|
|
|
fSettingsWindow->Show();
|
|
|
|
else
|
|
|
|
fSettingsWindow->Activate();
|
|
|
|
fSettingsWindow->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::CloseParentWindowCommon(BContainerWindow* window)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
ASSERT(fWindowList.IsLocked());
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
if (dynamic_cast<BDeskWindow*>(window))
|
2005-05-23 04:58:42 +04:00
|
|
|
// don't close the destop
|
|
|
|
return false;
|
|
|
|
|
|
|
|
window->PostMessage(B_QUIT_REQUESTED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::SelectChildInParent(const entry_ref* parent, const node_ref* child)
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
AutoLock<WindowList> lock(&fWindowList);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
BContainerWindow* window = FindContainerWindow(parent);
|
2009-06-14 14:57:09 +04:00
|
|
|
if (!window)
|
2005-05-23 04:58:42 +04:00
|
|
|
// parent window already closed, give up
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLock<BWindow> windowLock(window);
|
2009-06-14 14:57:09 +04:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (windowLock.IsLocked()) {
|
2012-07-28 03:07:09 +04:00
|
|
|
BPoseView* view = window->PoseView();
|
2005-05-23 04:58:42 +04:00
|
|
|
int32 index;
|
2012-07-28 03:07:09 +04:00
|
|
|
BPose* pose = view->FindPose(child, &index);
|
2005-05-23 04:58:42 +04:00
|
|
|
if (pose) {
|
|
|
|
view->SelectPose(pose, index);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
return false;
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const int32 kNodeMonitorBumpValue = 512;
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
status_t
|
2005-05-23 04:58:42 +04:00
|
|
|
TTracker::NeedMoreNodeMonitors()
|
|
|
|
{
|
|
|
|
fNodeMonitorCount += kNodeMonitorBumpValue;
|
2010-09-12 19:09:14 +04:00
|
|
|
PRINT(("bumping nodeMonitorCount to %" B_PRId32 "\n", fNodeMonitorCount));
|
2005-05-23 04:58:42 +04:00
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
struct rlimit rl;
|
|
|
|
rl.rlim_cur = fNodeMonitorCount;
|
|
|
|
rl.rlim_max = RLIM_SAVED_MAX;
|
2010-01-17 15:15:50 +03:00
|
|
|
if (setrlimit(RLIMIT_NOVMON, &rl) < 0) {
|
|
|
|
fNodeMonitorCount -= kNodeMonitorBumpValue;
|
2009-06-14 14:57:09 +04:00
|
|
|
return errno;
|
2010-01-17 15:15:50 +03:00
|
|
|
}
|
2009-06-14 14:57:09 +04:00
|
|
|
return B_OK;
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::WatchNode(const node_ref* node, uint32 flags,
|
2005-05-23 04:58:42 +04:00
|
|
|
BMessenger target)
|
|
|
|
{
|
|
|
|
status_t result = watch_node(node, flags, target);
|
2005-12-31 15:34:37 +03:00
|
|
|
if (result == B_OK || result != B_NO_MEMORY) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// need to make sure this uses the same error value as
|
|
|
|
// the node monitor code
|
|
|
|
return result;
|
2005-12-31 15:34:37 +03:00
|
|
|
}
|
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
PRINT(("failed to start monitoring, trying to allocate more "
|
|
|
|
"node monitors\n"));
|
|
|
|
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker* tracker = dynamic_cast<TTracker*>(be_app);
|
2005-12-31 15:34:37 +03:00
|
|
|
if (!tracker) {
|
2005-05-23 04:58:42 +04:00
|
|
|
// we are the file panel only, just fail
|
|
|
|
return result;
|
2005-12-31 15:34:37 +03:00
|
|
|
}
|
2005-05-23 04:58:42 +04:00
|
|
|
|
|
|
|
result = tracker->NeedMoreNodeMonitors();
|
2005-12-31 15:34:37 +03:00
|
|
|
|
2005-05-23 04:58:42 +04:00
|
|
|
if (result != B_OK) {
|
|
|
|
PRINT(("failed to allocate more node monitors, %s\n",
|
|
|
|
strerror(result)));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try again, this time with more node monitors
|
|
|
|
return watch_node(node, flags, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 18:52:17 +04:00
|
|
|
BMessenger
|
|
|
|
TTracker::MountServer() const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
2009-10-12 18:52:17 +04:00
|
|
|
return BMessenger(kMountServerSignature);
|
2005-05-23 04:58:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-14 14:57:09 +04:00
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::InTrashNode(const entry_ref* node) const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
return FSInTrashDir(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
TTracker::TrashFull() const
|
|
|
|
{
|
|
|
|
return fTrashWatcher->CheckTrashDirs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2012-07-28 03:07:09 +04:00
|
|
|
TTracker::IsTrashNode(const node_ref* node) const
|
2005-05-23 04:58:42 +04:00
|
|
|
{
|
|
|
|
return fTrashWatcher->IsTrashNode(node);
|
2009-06-14 14:57:09 +04:00
|
|
|
}
|