本文整理汇总了C++中BQuery::Fetch方法的典型用法代码示例。如果您正苦于以下问题:C++ BQuery::Fetch方法的具体用法?C++ BQuery::Fetch怎么用?C++ BQuery::Fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BQuery
的用法示例。
在下文中一共展示了BQuery::Fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
POP3Protocol::CheckForDeletedMessages()
{
{
// Delete things from the manifest no longer on the server
BStringList list;
NotHere(fUniqueIDs, fManifest, &list);
fManifest.Remove(list);
}
if (!fSettings.FindBool("delete_remote_when_local")
|| fManifest.CountStrings() == 0)
return;
BStringList toDelete;
BStringList queryContents;
BVolumeRoster volumes;
BVolume volume;
while (volumes.GetNextVolume(&volume) == B_OK) {
BQuery fido;
entry_ref entry;
fido.SetVolume(&volume);
fido.PushAttr(B_MAIL_ATTR_ACCOUNT_ID);
fido.PushInt32(fAccountSettings.AccountID());
fido.PushOp(B_EQ);
fido.Fetch();
BString uid;
while (fido.GetNextRef(&entry) == B_OK) {
BNode(&entry).ReadAttrString("MAIL:unique_id", &uid);
queryContents.Add(uid);
}
}
NotHere(queryContents, fManifest, &toDelete);
for (int32 i = 0; i < toDelete.CountStrings(); i++) {
printf("delete mail on server uid %s\n", toDelete.StringAt(i).String());
Delete(fUniqueIDs.IndexOf(toDelete.StringAt(i)));
}
// Don't remove ids from fUniqueIDs, the indices have to stay the same when
// retrieving new messages.
fManifest.Remove(toDelete);
// TODO: at some point the purged manifest should be written to disk
// otherwise it will grow forever
}
示例2:
status_t
CDDBQuery::_OpenContentFile(const int32 &discID)
{
// Makes sure that the lookup has a valid file to work with for the CD content.
// Returns true if there is an existing file, false if a lookup is required.
BFile file;
BString predicate;
predicate << "CD:key == " << discID;
entry_ref ref;
BVolumeRoster roster;
BVolume volume;
roster.Rewind();
while (roster.GetNextVolume(&volume) == B_OK) {
if (volume.IsReadOnly() || !volume.IsPersistent() || !volume.KnowsAttr()
|| !volume.KnowsQuery())
continue;
// make sure the volume we are looking at is indexed right
fs_create_index(volume.Device(), "CD:key", B_INT32_TYPE, 0);
BQuery query;
query.SetVolume(&volume);
query.SetPredicate(predicate.String());
if (query.Fetch() != B_OK)
continue;
if (query.GetNextRef(&ref) == B_OK)
break;
}
status_t status = fCDData.Load(ref);
if (status == B_NO_INIT) {
// We receive this error when the Load() function couldn't load the track times
// This just means that we get it from the SCSI data given to us in SetToCD
vector<CDAudioTime> times;
GetTrackTimes(&fSCSIData,times);
for (int32 i = 0; i < fCDData.CountTracks(); i++) {
CDAudioTime *item = fCDData.TrackTimeAt(i);
*item = times[i + 1] - times[i];
}
status = B_OK;
}
return status;
}
示例3: filePath
status_t
TeamWindow::_RetrieveMatchingSourceEntries(const BString& path,
BStringList* _entries)
{
BPath filePath(path);
status_t error = filePath.InitCheck();
if (error != B_OK)
return error;
_entries->MakeEmpty();
BQuery query;
BString predicate;
query.PushAttr("name");
query.PushString(filePath.Leaf());
query.PushOp(B_EQ);
error = query.GetPredicate(&predicate);
if (error != B_OK)
return error;
BVolumeRoster roster;
BVolume volume;
while (roster.GetNextVolume(&volume) == B_OK) {
if (!volume.KnowsQuery())
continue;
if (query.SetVolume(&volume) != B_OK)
continue;
error = query.SetPredicate(predicate.String());
if (error != B_OK)
continue;
if (query.Fetch() != B_OK)
continue;
entry_ref ref;
while (query.GetNextRef(&ref) == B_OK) {
filePath.SetTo(&ref);
_entries->Add(filePath.Path());
}
query.Clear();
}
return B_OK;
}
示例4: file
int32
add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
const char* format, bool popup)
{
BVolume volume;
BVolumeRoster().GetBootVolume(&volume);
BQuery query;
query.SetVolume(&volume);
query.PushAttr(attribute);
query.PushString("*");
query.PushOp(B_EQ);
query.Fetch();
int32 index = 0;
BEntry entry;
while (query.GetNextEntry(&entry) == B_OK) {
BFile file(&entry, B_READ_ONLY);
if (file.InitCheck() == B_OK) {
BMessage* message = new BMessage(what);
entry_ref ref;
entry.GetRef(&ref);
message->AddRef("ref", &ref);
BString value;
if (file.ReadAttrString(attribute, &value) < B_OK)
continue;
message->AddString("attribute", value.String());
BString name;
if (format != NULL)
name.SetToFormat(format, value.String());
else
name = value;
if (index < 9 && !popup)
menu->AddItem(new BMenuItem(name, message, '1' + index));
else
menu->AddItem(new BMenuItem(name, message));
index++;
}
}
return index;
}
示例5: BPopUpMenu
BPopUpMenu*
TPrefsWindow::_BuildSignatureMenu(char* sig)
{
char name[B_FILE_NAME_LENGTH];
BEntry entry;
BFile file;
BMenuItem* item;
BMessage* msg;
BQuery query;
BVolume vol;
BVolumeRoster volume;
BPopUpMenu* menu = new BPopUpMenu("");
msg = new BMessage(P_SIG);
msg->AddString("signature", B_TRANSLATE("None"));
menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), msg));
if (!strcmp(sig, B_TRANSLATE("None")))
item->SetMarked(true);
msg = new BMessage(P_SIG);
msg->AddString("signature", B_TRANSLATE("Random"));
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Random"), msg));
if (!strcmp(sig, B_TRANSLATE("Random")))
item->SetMarked(true);
menu->AddSeparatorItem();
volume.GetBootVolume(&vol);
query.SetVolume(&vol);
query.SetPredicate("_signature = *");
query.Fetch();
while (query.GetNextEntry(&entry) == B_NO_ERROR) {
file.SetTo(&entry, O_RDONLY);
if (file.InitCheck() == B_NO_ERROR) {
msg = new BMessage(P_SIG);
file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name));
msg->AddString("signature", name);
menu->AddItem(item = new BMenuItem(name, msg));
if (!strcmp(sig, name))
item->SetMarked(true);
}
}
return menu;
}
示例6:
void
Feeder::AddQuery(BVolume *volume)
{
fVolumeList.AddItem((void*)volume) ;
BQuery *query = new BQuery ;
query->SetVolume(volume) ;
// query->SetPredicate("name = *.txt") ;
query->SetPredicate("last_modified > %now%") ;
query->SetTarget(this) ;
if (query->Fetch() == B_OK) {
RetrieveStaticRefs(query) ;
fQueryList.AddItem((void *)query) ;
} else
delete query ;
}
示例7:
bool
TStatusWindow::_Exists(const char* status)
{
BVolume volume;
BVolumeRoster().GetBootVolume(&volume);
BQuery query;
query.SetVolume(&volume);
query.PushAttr(INDEX_STATUS);
query.PushString(status);
query.PushOp(B_EQ);
query.Fetch();
BEntry entry;
if (query.GetNextEntry(&entry) == B_NO_ERROR)
return true;
return false;
}
示例8:
uint32
FetchQuery(query_op op, const char* selection, vector<BString>& results,
bool caseSensitive = false)
{
BQuery query;
query.PushAttr("BEOS:TYPE");
query.PushString("application/x-vnd.Be-doc_bookmark");
query.PushOp(B_EQ);
query.PushAttr("name");
query.PushString(selection, caseSensitive);
query.PushOp(op);
query.PushOp(B_AND);
BVolume vol;
BVolumeRoster roster;
roster.GetBootVolume(&vol);
query.SetVolume(&vol);
if (B_NO_INIT == query.Fetch())
return 0;
BEntry entry;
BPath path;
int32 counter = 0;
while (query.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
if (entry.InitCheck() == B_OK) {
entry.GetPath(&path);
if (path.InitCheck() == B_OK) {
results.push_back(path.Path());
counter++;
}
}
}
return counter;
}
示例9: volume
int
main(int argc, char** argv)
{
if (argc < 2) {
fprintf(stderr, "usage: %s <message-code>\n", __progname);
return -1;
}
int32 number = atol(argv[1]);
BQuery query;
query.SetPredicate("name=ServerProtocol.h");
// search on current volume only
dev_t device = dev_for_path(".");
BVolume volume(device);
query.SetVolume(&volume);
query.Fetch();
status_t status;
BEntry entry;
while ((status = query.GetNextEntry(&entry)) == B_OK) {
BPath path(&entry);
puts(path.Path());
if (strstr(path.Path(), "headers/private/app/ServerProtocol.h") != NULL) {
print_code(path, number);
break;
}
}
if (status != B_OK) {
fprintf(stderr, "%s: could not find ServerProtocol.h", __progname);
return -1;
}
return 0;
}
示例10: strchr
void
THeaderView::InitGroupCompletion()
{
// get boot volume
BVolume volume;
BVolumeRoster().GetBootVolume(&volume);
// Build a list of all unique groups and the addresses they expand to.
BQuery query;
query.SetVolume(&volume);
query.SetPredicate("META:group=**");
query.Fetch();
map<BString *, BString *, CompareBStrings> groupMap;
entry_ref ref;
BNode file;
while (query.GetNextRef(&ref) == B_OK) {
if (file.SetTo(&ref) != B_OK)
continue;
BString groups;
if (file.ReadAttrString("META:group", &groups) < B_OK || groups.Length() == 0)
continue;
BString address;
file.ReadAttrString("META:email", &address);
// avoid adding an empty address
if (address.Length() == 0)
continue;
char *group = groups.LockBuffer(groups.Length());
char *next = strchr(group, ',');
for (;;) {
if (next)
*next = 0;
while (*group && *group == ' ')
group++;
BString *groupString = new BString(group);
BString *addressListString = NULL;
// nobody is in this group yet, start it off
if (groupMap[groupString] == NULL) {
addressListString = new BString(*groupString);
addressListString->Append(" ");
groupMap[groupString] = addressListString;
} else {
addressListString = groupMap[groupString];
addressListString->Append(", ");
delete groupString;
}
// Append the user's address to the end of the string with the
// comma separated list of addresses. If not present, add the
// < and > brackets around the address.
if (address.FindFirst ('<') < 0) {
address.ReplaceAll ('>', '_');
address.Prepend ("<");
address.Append(">");
}
addressListString->Append(address);
if (!next)
break;
group = next + 1;
next = strchr(group, ',');
}
}
map<BString *, BString *, CompareBStrings>::iterator iter;
for (iter = groupMap.begin(); iter != groupMap.end();) {
BString *group = iter->first;
BString *addr = iter->second;
fEmailList.AddChoice(addr->String());
++iter;
groupMap.erase(group);
delete group;
delete addr;
}
}
示例11: file
void
PersonView::BuildGroupMenu()
{
if (fGroups == NULL)
return;
BMenuItem* item;
while ((item = fGroups->ItemAt(0)) != NULL) {
fGroups->RemoveItem(item);
delete item;
}
int32 count = 0;
BVolumeRoster volumeRoster;
BVolume volume;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
BQuery query;
query.SetVolume(&volume);
char buffer[256];
snprintf(buffer, sizeof(buffer), "%s=*", fCategoryAttribute.String());
query.SetPredicate(buffer);
query.Fetch();
BEntry entry;
while (query.GetNextEntry(&entry) == B_OK) {
BFile file(&entry, B_READ_ONLY);
attr_info info;
if (file.InitCheck() == B_OK
&& file.GetAttrInfo(fCategoryAttribute, &info) == B_OK
&& info.size > 1) {
if (info.size > (off_t)sizeof(buffer))
info.size = sizeof(buffer);
if (file.ReadAttr(fCategoryAttribute.String(), B_STRING_TYPE,
0, buffer, info.size) < 0) {
continue;
}
const char *text = buffer;
while (true) {
char* offset = strstr(text, ",");
if (offset != NULL)
offset[0] = '\0';
if (!fGroups->FindItem(text)) {
int32 index = 0;
while ((item = fGroups->ItemAt(index)) != NULL) {
if (strcmp(text, item->Label()) < 0)
break;
index++;
}
BMessage* message = new BMessage(M_GROUP_MENU);
message->AddString("group", text);
fGroups->AddItem(new BMenuItem(text, message), index);
count++;
}
if (offset) {
text = offset + 1;
while (*text == ' ')
text++;
}
else
break;
}
}
}
}
if (count == 0) {
fGroups->AddItem(item = new BMenuItem(
B_TRANSLATE_CONTEXT("none", "Groups list"),
new BMessage(M_GROUP_MENU)));
item->SetEnabled(false);
}
fGroups->SetTargetForItems(this);
}
示例12: currentPath
int
main(int argc, char* argv[])
{
team_info teamInfo;
int32 cookie = 0;
while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
if (!strncmp(teamInfo.args, "/boot/beos/", 11)
|| !strncmp(teamInfo.args, "/boot/system/", 13)) {
// this is a system component and not worth to investigate
continue;
}
thread_info threadInfo;
int32 threadCookie = 0;
while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo)
== B_OK) {
// search for the roster thread
if (!strcmp(threadInfo.name, "_roster_thread_")) {
port_id port = find_port("haiku-test:roster");
port_info portInfo;
if (get_port_info(port, &portInfo) == B_OK
&& portInfo.team == teamInfo.team) {
puts("The Haiku Registrar is already running.");
return 0;
}
}
}
}
// the Haiku registrar doesn't seem to run yet, change this
BPath currentPath(".");
BQuery query;
query.SetPredicate("name==test_registrar");
// search on current volume only
dev_t device = dev_for_path(".");
BVolume volume(device);
query.SetVolume(&volume);
query.Fetch();
entry_ref ref;
while (query.GetNextRef(&ref) == B_OK) {
BPath path(&ref);
if (path.InitCheck() != B_OK)
continue;
const char* registrarPath = path.Path();
const char* generatedPath = strstr(registrarPath, "generated");
if (generatedPath == NULL)
continue;
if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) {
// gotcha!
if (launch_registrar(registrarPath) == B_OK)
return 0;
}
}
// As a fallback (maybe the volume does not support queries for example)
// try to find the test_registrar in the current folder...
BString registrarPath(argv[0]);
registrarPath.RemoveLast(__progname);
registrarPath.Append("test_registrar");
if (launch_registrar(registrarPath.String()) == B_OK)
return 0;
fprintf(stderr, "%s: Could not find the Haiku Registrar.\n"
" (This tool only works when used in the Haiku tree, but maybe\n"
" the registrar just needs to be built.)\n",
__progname);
return -1;
}
示例13: ProgressWindow
void
ApplicationTypesWindow::_RemoveUninstalled()
{
// Note: this runs in the looper's thread, which isn't that nice
int32 removed = 0;
volatile bool quit = false;
BWindow* progressWindow =
new ProgressWindow(
B_TRANSLATE("Removing uninstalled application types"),
fTypeListView->FullListCountItems(), &quit);
progressWindow->AddToSubset(this);
progressWindow->Show();
for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) {
MimeTypeItem* item = dynamic_cast<MimeTypeItem*>
(fTypeListView->FullListItemAt(i));
progressWindow->PostMessage(B_UPDATE_STATUS_BAR);
if (item == NULL)
continue;
// search for application on all volumes
bool found = false;
BVolumeRoster volumeRoster;
BVolume volume;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
if (!volume.KnowsQuery())
continue;
BQuery query;
query.PushAttr("BEOS:APP_SIG");
query.PushString(item->Type());
query.PushOp(B_EQ);
query.SetVolume(&volume);
query.Fetch();
entry_ref ref;
if (query.GetNextRef(&ref) == B_OK) {
found = true;
break;
}
}
if (!found) {
BMimeType mimeType(item->Type());
mimeType.Delete();
removed++;
// We're blocking the message loop that received the MIME changes,
// so we dequeue all waiting messages from time to time
if (removed % 10 == 0)
UpdateIfNeeded();
}
}
progressWindow->PostMessage(B_QUIT_REQUESTED);
static BMessageFormat format(B_TRANSLATE("{0, plural, "
"one{# Application type could be removed} "
"other{# Application types could be removed}}"));
BString message;
format.Format(message, removed);
error_alert(message, B_OK, B_INFO_ALERT);
}
示例14: currentPath
int
main()
{
team_info teamInfo;
int32 cookie = 0;
while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
if (!strncmp(teamInfo.args, "/boot/beos/", 11)) {
// this is a system component and not worth to investigate
continue;
}
thread_info threadInfo;
int32 threadCookie = 0;
while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo)
== B_OK) {
// search for the roster thread
if (!strcmp(threadInfo.name, "_roster_thread_")) {
port_id port = find_port("antares-test:roster");
port_info portInfo;
if (get_port_info(port, &portInfo) == B_OK
&& portInfo.team == teamInfo.team) {
puts("The Antares Registrar is already running.");
return 0;
}
}
}
}
// the Antares registrar doesn't seem to run yet, change this
BPath currentPath(".");
BQuery query;
query.SetPredicate("name==test_registrar");
// search on current volume only
dev_t device = dev_for_path(".");
BVolume volume(device);
query.SetVolume(&volume);
query.Fetch();
entry_ref ref;
while (query.GetNextRef(&ref) == B_OK) {
BPath path(&ref);
if (path.InitCheck() != B_OK)
continue;
const char* registrarPath = path.Path();
const char* generatedPath = strstr(registrarPath, "generated");
if (generatedPath == NULL)
continue;
if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) {
// gotcha!
const char* args[] = { registrarPath, NULL };
thread_id thread = load_image(1, args, (const char**)environ);
if (thread < B_OK) {
fprintf(stderr, "%s: Could not start the registrar: %s\n",
__progname, strerror(thread));
return -1;
}
resume_thread(thread);
return 0;
}
}
fprintf(stderr, "%s: Could not find the Antares Registrar.\n"
" (This tool only works when used in the Antares tree, but maybe\n"
" the registrar just needs to be built.)\n",
__progname);
return -1;
}
示例15: MessageReceived
void QueryLooper::MessageReceived(BMessage *msg) {
switch (msg->what) {
case B_QUERY_UPDATE: {
int32 opcode = 0;
entry_ref affected;
if (msg->FindInt32("opcode", &opcode) != B_OK) return;
switch (opcode) {
case B_ENTRY_CREATED: {
result r;
const char *name;
msg->FindInt32("device", &r.ref.device);
msg->FindInt64("directory", &r.ref.directory);
msg->FindString("name", &name);
r.ref.set_name(name);
msg->FindInt32("device", &r.nref.device);
msg->FindInt64("node", &r.nref.node);
fResults[r.ref] = r;
affected = r.ref;
} break;
case B_ENTRY_REMOVED: {
node_ref nref;
result_t::iterator rIt;
msg->FindInt32("device", &nref.device);
msg->FindInt64("node", &nref.node);
for (rIt = fResults.begin(); rIt != fResults.end(); rIt++) {
result r = rIt->second;
if (nref == r.nref) {
fResults.erase(r.ref);
affected = r.ref;
break;
};
};
} break;
};
if ((fNotify.IsValid()) && (fMsg != NULL)) {
BMessage notify(*fMsg);
notify.AddString("qlName", fName);
notify.AddRef("affected_ref", &affected);
if (opcode == B_ENTRY_CREATED) {
notify.AddInt32("query_what", Notifications::EntryAdded);
} else {
notify.AddInt32("query_what", Notifications::EntryRemoved);
};
#if B_BEOS_VERSION > B_BEOS_VERSION_5
fNotify.SendMessage(notify);
#else
fNotify.SendMessage(¬ify);
#endif
};
} break;
case msgInitialFetch: {
volume_t::iterator vIt;
for (vIt = fVolumes.begin(); vIt != fVolumes.end(); vIt++) {
BVolume vol = (*vIt);
BQuery *query = new BQuery();
query->SetPredicate(fPredicate.String());
query->SetTarget(this);
query->SetVolume(&vol);
query->Fetch();
entry_ref ref;
while (query->GetNextRef(&ref) == B_OK) {
BNode node(&ref);
result r;
r.ref = ref;
node.GetNodeRef(&r.nref);
fResults[ref] = r;
};
fQueries.push_back(query);
};
if ((fNotify.IsValid()) && (fMsg != NULL)) {
BMessage notify(*fMsg);
notify.AddString("qlName", fName);
notify.AddInt32("query_what", Notifications::InitialFetch);
#if B_BEOS_VERSION > B_BEOS_VERSION_5
fNotify.SendMessage(notify);
#else
fNotify.SendMessage(¬ify);
#endif
};
} break;
//.........这里部分代码省略.........