* The recent app list now filters out Tracker & Deskbar, as reported by Korli.
* The application signatures now preserve the case; this is better for querying after the app, and has no disadvantage. * Adding an item to the list is now guarded by a try/catch block - allocations can fail, and the registrar shouldn't get down because of this. We need to proof-read all of registrar (and storage kit) for this :-/ * Get() did not populate an eventual error while adding items to the provided list (such as B_NO_MEMORY). * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19261 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bef4e1fc77
commit
ddacfc7ff0
@ -4,6 +4,7 @@ UsePrivateHeaders app ;
|
||||
UsePrivateHeaders kernel ;
|
||||
UsePrivateHeaders shared ;
|
||||
UsePrivateHeaders storage ;
|
||||
UsePrivateHeaders tracker ;
|
||||
UseArchHeaders $(TARGET_ARCH) ;
|
||||
|
||||
Server registrar
|
||||
|
@ -1,34 +1,19 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// 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 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 MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS 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.
|
||||
//
|
||||
// File Name: RecentApps.cpp
|
||||
// Author: Tyler Dauwalder (tyler@dauwalder.net)
|
||||
// Description: Recently launched apps list
|
||||
//------------------------------------------------------------------------------
|
||||
/*! \file RecentApps.cpp
|
||||
\brief RecentApps class implementation
|
||||
/*
|
||||
* Copyright 2001-2006, Haiku Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Tyler Dauwalder
|
||||
* Ingo Weinhold, bonefish@users.sf.net
|
||||
* Axel Dörfler, axeld@pinc-software.de
|
||||
*/
|
||||
|
||||
//! Recently launched apps list
|
||||
|
||||
#include "RecentApps.h"
|
||||
|
||||
#include <tracker_private.h>
|
||||
|
||||
#include <AppFileInfo.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
@ -53,7 +38,7 @@
|
||||
signatures are case-independent.
|
||||
*/
|
||||
|
||||
// constructor
|
||||
|
||||
/*! \brief Creates a new list.
|
||||
|
||||
The list is initially empty.
|
||||
@ -62,7 +47,7 @@ RecentApps::RecentApps()
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
/*! \brief Frees all resources associated with the object.
|
||||
|
||||
Currently does nothing.
|
||||
@ -71,7 +56,7 @@ RecentApps::~RecentApps()
|
||||
{
|
||||
}
|
||||
|
||||
// Add
|
||||
|
||||
/*! \brief Places the app with the given signature at the front of
|
||||
the recent apps list.
|
||||
|
||||
@ -90,27 +75,36 @@ RecentApps::~RecentApps()
|
||||
status_t
|
||||
RecentApps::Add(const char *appSig, int32 appFlags)
|
||||
{
|
||||
status_t err = appSig ? B_OK : B_BAD_VALUE;
|
||||
if (!err && !(appFlags & B_ARGV_ONLY) && !(appFlags & B_BACKGROUND_APP)) {
|
||||
// Store all sigs as lowercase
|
||||
std::string sig = BPrivate::Storage::to_lower(appSig);
|
||||
if (appSig == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// don't add background apps, as well as Tracker and Deskbar to the list
|
||||
// of recent apps
|
||||
if (!strcasecmp(appSig, kTrackerSignature)
|
||||
|| !strcasecmp(appSig, kDeskbarSignature)
|
||||
|| (appFlags & B_ARGV_ONLY) != 0 || (appFlags & B_BACKGROUND_APP) != 0)
|
||||
return B_OK;
|
||||
|
||||
// Remove any previous instance
|
||||
std::list<std::string>::iterator i;
|
||||
for (i = fAppList.begin(); i != fAppList.end(); i++) {
|
||||
if (*i == sig) {
|
||||
if (!strcasecmp((*i).c_str(), appSig)) {
|
||||
fAppList.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Add to the front
|
||||
fAppList.push_front(sig);
|
||||
fAppList.push_front(appSig);
|
||||
} catch (...) {
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
return err;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// Add
|
||||
|
||||
/*! \brief Adds the signature of the application referred to by \a ref at
|
||||
the front of the recent apps list.
|
||||
|
||||
@ -121,13 +115,14 @@ RecentApps::Add(const char *appSig, int32 appFlags)
|
||||
status_t
|
||||
RecentApps::Add(const entry_ref *ref, int32 appFlags)
|
||||
{
|
||||
if (ref == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
BFile file;
|
||||
BAppFileInfo info;
|
||||
char signature[B_MIME_TYPE_LENGTH];
|
||||
|
||||
status_t err = ref ? B_OK : B_BAD_VALUE;
|
||||
if (!err)
|
||||
err = file.SetTo(ref, B_READ_ONLY);
|
||||
status_t err = file.SetTo(ref, B_READ_ONLY);
|
||||
if (!err)
|
||||
err = info.SetTo(&file);
|
||||
if (!err)
|
||||
@ -137,7 +132,7 @@ RecentApps::Add(const entry_ref *ref, int32 appFlags)
|
||||
return err;
|
||||
}
|
||||
|
||||
// Get
|
||||
|
||||
/*! \brief Returns the first \a maxCount recent apps in the \c BMessage
|
||||
pointed to by \a list.
|
||||
|
||||
@ -153,31 +148,30 @@ RecentApps::Add(const entry_ref *ref, int32 appFlags)
|
||||
status_t
|
||||
RecentApps::Get(int32 maxCount, BMessage *list)
|
||||
{
|
||||
status_t err = list ? B_OK : B_BAD_VALUE;
|
||||
if (!err) {
|
||||
if (list == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// Clear
|
||||
list->MakeEmpty();
|
||||
|
||||
// Fill
|
||||
std::list<std::string>::iterator item;
|
||||
status_t status = B_OK;
|
||||
int counter = 0;
|
||||
for (item = fAppList.begin();
|
||||
counter < maxCount && item != fAppList.end();
|
||||
counter++, item++)
|
||||
{
|
||||
status == B_OK && counter < maxCount && item != fAppList.end();
|
||||
counter++, item++) {
|
||||
entry_ref ref;
|
||||
status_t error = GetRefForApp(item->c_str(), &ref);
|
||||
if (!error)
|
||||
list->AddRef("refs", &ref);
|
||||
if (GetRefForApp(item->c_str(), &ref) == B_OK)
|
||||
status = list->AddRef("refs", &ref);
|
||||
else
|
||||
DBG(OUT("WARNING: RecentApps::Get(): No ref found for app '%s'\n", item->c_str()));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// Clear
|
||||
/*! \brief Clears the list of recently launched apps
|
||||
*/
|
||||
status_t
|
||||
@ -187,7 +181,7 @@ RecentApps::Clear()
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// Print
|
||||
|
||||
/*! \brief Dumps the the current list of apps to stdout.
|
||||
*/
|
||||
status_t
|
||||
@ -195,16 +189,13 @@ RecentApps::Print()
|
||||
{
|
||||
std::list<std::string>::iterator item;
|
||||
int counter = 1;
|
||||
for (item = fAppList.begin();
|
||||
item != fAppList.end();
|
||||
item++)
|
||||
{
|
||||
for (item = fAppList.begin(); item != fAppList.end(); item++) {
|
||||
printf("%d: '%s'\n", counter++, item->c_str());
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// Save
|
||||
|
||||
/*! \brief Outputs a textual representation of the current recent
|
||||
apps list to the given file stream.
|
||||
|
||||
@ -216,10 +207,7 @@ RecentApps::Save(FILE* file)
|
||||
if (!error) {
|
||||
fprintf(file, "# Recent applications\n");
|
||||
std::list<std::string>::iterator item;
|
||||
for (item = fAppList.begin();
|
||||
item != fAppList.end();
|
||||
item++)
|
||||
{
|
||||
for (item = fAppList.begin(); item != fAppList.end(); item++) {
|
||||
fprintf(file, "RecentApp %s\n", item->c_str());
|
||||
}
|
||||
fprintf(file, "\n");
|
||||
@ -227,7 +215,7 @@ RecentApps::Save(FILE* file)
|
||||
return error;
|
||||
}
|
||||
|
||||
// GetRefForApp
|
||||
|
||||
/*! \brief Fetches an \c entry_ref for the application with the
|
||||
given signature.
|
||||
|
||||
@ -238,12 +226,13 @@ RecentApps::Save(FILE* file)
|
||||
status_t
|
||||
RecentApps::GetRefForApp(const char *appSig, entry_ref *result)
|
||||
{
|
||||
status_t err = appSig && result ? B_OK : B_BAD_VALUE;
|
||||
if (appSig == NULL || result == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
// We'll use BMimeType to check for the app hint, since I'm lazy
|
||||
// and Ingo's on vacation :-P :-)
|
||||
BMimeType mime(appSig);
|
||||
err = mime.InitCheck();
|
||||
status_t err = mime.InitCheck();
|
||||
if (!err)
|
||||
err = mime.GetAppHint(result);
|
||||
return err;
|
||||
|
Loading…
Reference in New Issue
Block a user