* 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:
Axel Dörfler 2006-11-12 17:16:13 +00:00
parent bef4e1fc77
commit ddacfc7ff0
2 changed files with 78 additions and 88 deletions

View File

@ -4,6 +4,7 @@ UsePrivateHeaders app ;
UsePrivateHeaders kernel ; UsePrivateHeaders kernel ;
UsePrivateHeaders shared ; UsePrivateHeaders shared ;
UsePrivateHeaders storage ; UsePrivateHeaders storage ;
UsePrivateHeaders tracker ;
UseArchHeaders $(TARGET_ARCH) ; UseArchHeaders $(TARGET_ARCH) ;
Server registrar Server registrar

View File

@ -1,34 +1,19 @@
//------------------------------------------------------------------------------ /*
// Copyright (c) 2001-2002, OpenBeOS * Copyright 2001-2006, Haiku Inc.
// * Distributed under the terms of the MIT License.
// Permission is hereby granted, free of charge, to any person obtaining a *
// copy of this software and associated documentation files (the "Software"), * Authors:
// to deal in the Software without restriction, including without limitation * Tyler Dauwalder
// the rights to use, copy, modify, merge, publish, distribute, sublicense, * Ingo Weinhold, bonefish@users.sf.net
// and/or sell copies of the Software, and to permit persons to whom the * Axel Dörfler, axeld@pinc-software.de
// Software is furnished to do so, subject to the following conditions: */
//
// The above copyright notice and this permission notice shall be included in //! Recently launched apps list
// 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
*/
#include "RecentApps.h" #include "RecentApps.h"
#include <tracker_private.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
@ -53,7 +38,7 @@
signatures are case-independent. signatures are case-independent.
*/ */
// constructor
/*! \brief Creates a new list. /*! \brief Creates a new list.
The list is initially empty. The list is initially empty.
@ -62,7 +47,7 @@ RecentApps::RecentApps()
{ {
} }
// destructor
/*! \brief Frees all resources associated with the object. /*! \brief Frees all resources associated with the object.
Currently does nothing. Currently does nothing.
@ -71,7 +56,7 @@ RecentApps::~RecentApps()
{ {
} }
// Add
/*! \brief Places the app with the given signature at the front of /*! \brief Places the app with the given signature at the front of
the recent apps list. the recent apps list.
@ -90,27 +75,36 @@ RecentApps::~RecentApps()
status_t status_t
RecentApps::Add(const char *appSig, int32 appFlags) RecentApps::Add(const char *appSig, int32 appFlags)
{ {
status_t err = appSig ? B_OK : B_BAD_VALUE; if (appSig == NULL)
if (!err && !(appFlags & B_ARGV_ONLY) && !(appFlags & B_BACKGROUND_APP)) { return B_BAD_VALUE;
// Store all sigs as lowercase
std::string sig = BPrivate::Storage::to_lower(appSig); // don't add background apps, as well as Tracker and Deskbar to the list
// of recent apps
// Remove any previous instance if (!strcasecmp(appSig, kTrackerSignature)
std::list<std::string>::iterator i; || !strcasecmp(appSig, kDeskbarSignature)
for (i = fAppList.begin(); i != fAppList.end(); i++) { || (appFlags & B_ARGV_ONLY) != 0 || (appFlags & B_BACKGROUND_APP) != 0)
if (*i == sig) { return B_OK;
fAppList.erase(i);
break; // Remove any previous instance
} std::list<std::string>::iterator i;
for (i = fAppList.begin(); i != fAppList.end(); i++) {
if (!strcasecmp((*i).c_str(), appSig)) {
fAppList.erase(i);
break;
} }
// Add to the front
fAppList.push_front(sig);
} }
return err; try {
// Add to the front
fAppList.push_front(appSig);
} catch (...) {
return B_NO_MEMORY;
}
return B_OK;
} }
// Add
/*! \brief Adds the signature of the application referred to by \a ref at /*! \brief Adds the signature of the application referred to by \a ref at
the front of the recent apps list. the front of the recent apps list.
@ -121,13 +115,14 @@ RecentApps::Add(const char *appSig, int32 appFlags)
status_t status_t
RecentApps::Add(const entry_ref *ref, int32 appFlags) RecentApps::Add(const entry_ref *ref, int32 appFlags)
{ {
if (ref == NULL)
return B_BAD_VALUE;
BFile file; BFile file;
BAppFileInfo info; BAppFileInfo info;
char signature[B_MIME_TYPE_LENGTH]; char signature[B_MIME_TYPE_LENGTH];
status_t err = ref ? B_OK : B_BAD_VALUE; status_t err = file.SetTo(ref, B_READ_ONLY);
if (!err)
err = file.SetTo(ref, B_READ_ONLY);
if (!err) if (!err)
err = info.SetTo(&file); err = info.SetTo(&file);
if (!err) if (!err)
@ -137,7 +132,7 @@ RecentApps::Add(const entry_ref *ref, int32 appFlags)
return err; return err;
} }
// Get
/*! \brief Returns the first \a maxCount recent apps in the \c BMessage /*! \brief Returns the first \a maxCount recent apps in the \c BMessage
pointed to by \a list. pointed to by \a list.
@ -153,31 +148,30 @@ RecentApps::Add(const entry_ref *ref, int32 appFlags)
status_t status_t
RecentApps::Get(int32 maxCount, BMessage *list) RecentApps::Get(int32 maxCount, BMessage *list)
{ {
status_t err = list ? B_OK : B_BAD_VALUE; if (list == NULL)
if (!err) { return B_BAD_VALUE;
// Clear
list->MakeEmpty(); // Clear
list->MakeEmpty();
// Fill
std::list<std::string>::iterator item; // Fill
int counter = 0; std::list<std::string>::iterator item;
for (item = fAppList.begin(); status_t status = B_OK;
counter < maxCount && item != fAppList.end(); int counter = 0;
counter++, item++) for (item = fAppList.begin();
{ status == B_OK && counter < maxCount && item != fAppList.end();
entry_ref ref; counter++, item++) {
status_t error = GetRefForApp(item->c_str(), &ref); entry_ref ref;
if (!error) if (GetRefForApp(item->c_str(), &ref) == B_OK)
list->AddRef("refs", &ref); status = list->AddRef("refs", &ref);
else else
DBG(OUT("WARNING: RecentApps::Get(): No ref found for app '%s'\n", item->c_str())); DBG(OUT("WARNING: RecentApps::Get(): No ref found for app '%s'\n", item->c_str()));
}
} }
return err; return status;
} }
// Clear
/*! \brief Clears the list of recently launched apps /*! \brief Clears the list of recently launched apps
*/ */
status_t status_t
@ -187,7 +181,7 @@ RecentApps::Clear()
return B_OK; return B_OK;
} }
// Print
/*! \brief Dumps the the current list of apps to stdout. /*! \brief Dumps the the current list of apps to stdout.
*/ */
status_t status_t
@ -195,16 +189,13 @@ RecentApps::Print()
{ {
std::list<std::string>::iterator item; std::list<std::string>::iterator item;
int counter = 1; int counter = 1;
for (item = fAppList.begin(); for (item = fAppList.begin(); item != fAppList.end(); item++) {
item != fAppList.end();
item++)
{
printf("%d: '%s'\n", counter++, item->c_str()); printf("%d: '%s'\n", counter++, item->c_str());
} }
return B_OK; return B_OK;
} }
// Save
/*! \brief Outputs a textual representation of the current recent /*! \brief Outputs a textual representation of the current recent
apps list to the given file stream. apps list to the given file stream.
@ -216,10 +207,7 @@ RecentApps::Save(FILE* file)
if (!error) { if (!error) {
fprintf(file, "# Recent applications\n"); fprintf(file, "# Recent applications\n");
std::list<std::string>::iterator item; std::list<std::string>::iterator item;
for (item = fAppList.begin(); for (item = fAppList.begin(); item != fAppList.end(); item++) {
item != fAppList.end();
item++)
{
fprintf(file, "RecentApp %s\n", item->c_str()); fprintf(file, "RecentApp %s\n", item->c_str());
} }
fprintf(file, "\n"); fprintf(file, "\n");
@ -227,7 +215,7 @@ RecentApps::Save(FILE* file)
return error; return error;
} }
// GetRefForApp
/*! \brief Fetches an \c entry_ref for the application with the /*! \brief Fetches an \c entry_ref for the application with the
given signature. given signature.
@ -238,12 +226,13 @@ RecentApps::Save(FILE* file)
status_t status_t
RecentApps::GetRefForApp(const char *appSig, entry_ref *result) 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 // We'll use BMimeType to check for the app hint, since I'm lazy
// and Ingo's on vacation :-P :-) // and Ingo's on vacation :-P :-)
BMimeType mime(appSig); BMimeType mime(appSig);
err = mime.InitCheck(); status_t err = mime.InitCheck();
if (!err) if (!err)
err = mime.GetAppHint(result); err = mime.GetAppHint(result);
return err; return err;