status_t QueryEntryListCollection::FetchOneQuery(const BQuery* copyThis, BHandler* target, BObjectList<BQuery>* list, BVolume* volume) { BQuery* query = new (nothrow) BQuery; if (query == NULL) return B_NO_MEMORY; // have to fake a copy constructor here because BQuery doesn't have // a copy constructor BString buffer; const_cast<BQuery*>(copyThis)->GetPredicate(&buffer); query->SetPredicate(buffer.String()); query->SetTarget(BMessenger(target)); query->SetVolume(volume); status_t result = query->Fetch(); if (result != B_OK) { PRINT(("fetch error %s\n", strerror(result))); delete query; return result; } list->AddItem(query); return B_OK; }
void LiveQuery::MessageReceived(BMessage* message) { switch (message->what) { case kMsgAddQuery: { int32 device; const char* predicate; if (message->FindInt32("volume", &device) != B_OK || message->FindString("predicate", &predicate) != B_OK) break; BVolume volume(device); BQuery* query = new BQuery; // Set up the volume and predicate for the query. query->SetVolume(&volume); query->SetPredicate(predicate); query->SetTarget(this); fQueries.AddItem(query); _PerformQuery(*query); break; } case B_QUERY_UPDATE: { int32 what; message->FindInt32("opcode", &what); int32 device; int64 directory; int64 node; const char* name; message->FindInt32("device", &device); message->FindInt64("directory", &directory); message->FindInt64("node", &node); message->FindString("name", &name); switch (what) { case B_ENTRY_CREATED: { printf("CREATED %s\n", name); break; } case B_ENTRY_REMOVED: printf("REMOVED %s\n", name); break; } break; } default: BApplication::MessageReceived(message); break; } }
void QueryView::GetInitialEntries() { fEntryCount = 0; entry_ref ref; // slaad BNode n(&ref); vollist vols; ExtractQueryVolumes(&n, &vols); vollist::iterator vIt; for (vIt = vols.begin(); vIt != vols.end(); vIt++) { BQuery *query = new BQuery(); query->SetVolume(&(*vIt)); query->SetPredicate(fPredicate.String()); query->SetTarget(this); query->Fetch(); while( query->GetNextRef(&ref) == B_OK ) { // eiman BEntry entry(&ref); node_ref node; entry.GetNodeRef(&node); BMessage msg; msg.AddInt32("opcode",B_ENTRY_CREATED); msg.AddString("name",ref.name); msg.AddInt64("directory",ref.directory); msg.AddInt32("device",ref.device); msg.AddInt64("node",node.node); if ( !ShouldIgnore(&msg) ) { fEntryCount++; } } fQueries.push_back(query); }; #ifdef DEBUG BeDC dc("QueryWatcher"); BString str; str<<Name()<<" initial count: "<<fEntryCount; dc.SendMessage(str.String()); #endif UpdateDisplay(); }
void MailDaemonApp::ReadyToRun() { InstallDeskbarIcon(); _InitAccounts(); _UpdateAutoCheck(fSettingsFile.AutoCheckInterval()); BVolume volume; BVolumeRoster roster; fNewMessages = 0; while (roster.GetNextVolume(&volume) == B_OK) { //{char name[255];volume.GetName(name);printf("Volume: %s\n",name);} BQuery* query = new BQuery; query->SetTarget(this); query->SetVolume(&volume); query->PushAttr(B_MAIL_ATTR_STATUS); query->PushString("New"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-email"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-partial-email"); query->PushOp(B_EQ); query->PushOp(B_OR); query->PushOp(B_AND); query->Fetch(); BEntry entry; while (query->GetNextEntry(&entry) == B_OK) fNewMessages++; fQueries.AddItem(query); } BString string; MDR_DIALECT_CHOICE( if (fNewMessages > 0) string << fNewMessages; else string << "No"; if (fNewMessages != 1) string << " new messages."; else string << " new message.";, if (fNewMessages > 0)
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 ; }
void DeskbarView::_RefreshMailQuery() { for (int32 i = 0; i < fNewMailQueries.CountItems(); i++) delete ((BQuery *)(fNewMailQueries.ItemAt(i))); fNewMailQueries.MakeEmpty(); BVolumeRoster volumes; BVolume volume; fNewMessages = 0; while (volumes.GetNextVolume(&volume) == B_OK) { BQuery *newMailQuery = new BQuery; newMailQuery->SetTarget(this); newMailQuery->SetVolume(&volume); newMailQuery->PushAttr(B_MAIL_ATTR_READ); newMailQuery->PushInt32(B_UNREAD); newMailQuery->PushOp(B_EQ); newMailQuery->PushAttr("BEOS:TYPE"); newMailQuery->PushString("text/x-email"); newMailQuery->PushOp(B_EQ); newMailQuery->PushAttr("BEOS:TYPE"); newMailQuery->PushString("text/x-partial-email"); newMailQuery->PushOp(B_EQ); newMailQuery->PushOp(B_OR); newMailQuery->PushOp(B_AND); newMailQuery->Fetch(); BEntry entry; while (newMailQuery->GetNextEntry(&entry) == B_OK) { if (entry.InitCheck() == B_OK) { entry_ref ref; entry.GetRef(&ref); if (!_EntryInTrash(&ref)) fNewMessages++; } } fNewMailQueries.AddItem(newMailQuery); } fStatus = (fNewMessages > 0) ? kStatusNewMail : kStatusNoMail; Invalidate(); }
void MailDaemonApp::ReadyToRun() { InstallDeskbarIcon(); _InitAccounts(); _UpdateAutoCheck(fSettingsFile.AutoCheckInterval()); BVolume volume; BVolumeRoster roster; fNewMessages = 0; while (roster.GetNextVolume(&volume) == B_OK) { BQuery* query = new BQuery; query->SetTarget(this); query->SetVolume(&volume); query->PushAttr(B_MAIL_ATTR_STATUS); query->PushString("New"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-email"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-partial-email"); query->PushOp(B_EQ); query->PushOp(B_OR); query->PushOp(B_AND); query->Fetch(); BEntry entry; while (query->GetNextEntry(&entry) == B_OK) fNewMessages++; fQueries.AddItem(query); } BString string, numString; if (fNewMessages > 0) { if (fNewMessages != 1) string << B_TRANSLATE("%num new messages."); else string << B_TRANSLATE("%num new message."); numString << fNewMessages; string.ReplaceFirst("%num", numString); } else string = B_TRANSLATE("No new messages"); fCentralBeep = false; fNotification = new BNotification(B_INFORMATION_NOTIFICATION); fNotification->SetGroup(B_TRANSLATE("Mail status")); fNotification->SetTitle(string); fNotification->SetMessageID("daemon_status"); app_info info; be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info); BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); BNode node(&info.ref); BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); fNotification->SetIcon(&icon); fLEDAnimation = new LEDAnimation; SetPulseRate(1000000); }
/*********************************************************** * Fetching ***********************************************************/ void HQueryItem::Fetching() { bool some_success = false; BVolume volume; BVolumeRoster roster; while (fQueries.CountItems()) { delete static_cast<BQuery *>(fQueries.RemoveItem((int32)0)); } uint32 count_items = 0; while (roster.GetNextVolume(&volume) == B_OK) { BQuery *query = new BQuery; fQueries.AddItem((void*)query); query->Clear(); query->SetTarget(*fMessenger); query->SetVolume(&volume); query->SetPredicate(fPredicate.String()); char type[B_MIME_TYPE_LENGTH+1]; BNode node; HMailItem *item(NULL); if(query->Fetch() == B_OK) { some_success = true; entry_ref ref; char buf[4096]; dirent *dent; int32 count; int32 offset; while (((count = query->GetNextDirents((dirent *)buf, 4096)) > 0) && (!fCancel)) { offset = 0; /* Now we step through the dirents. */ while (count-- > 0) { dent = (dirent *)buf + offset; offset += dent->d_reclen; /* Skip . and .. directory */ if(::strcmp(dent->d_name,".") == 0 || ::strcmp(dent->d_name,"..")== 0) continue; ref.device = dent->d_pdev; ref.directory = dent->d_pino; ref.set_name(dent->d_name); if(node.SetTo(&ref) != B_OK) continue; node.ReadAttr("BEOS:TYPE",'MIMS',0,type,B_MIME_TYPE_LENGTH); if(::strcmp(type,B_MAIL_TYPE) == 0) { fMailList.AddItem(item = new HMailItem(ref)); if(item && !item->IsRead() ) count_items++; } } } }DEBUG_ONLY( else{ PRINT(("Query fetching was failed\n")); } ); }
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; default: { BLooper::MessageReceived(msg); }; }; };