[prev in list] [next in list] [prev in thread] [next in thread]
List: openbeos
Subject: [haiku] Re: Query and time
From: Michele Frau <zumikkebe () gmail ! com>
Date: 2020-10-14 8:19:19
Message-ID: CA+-e+rN-PTzNS3t-xGiJk6SSn4PVso9T4GP57ewOxiqXik4YOg () mail ! gmail ! com
[Download RAW message or body]
Hello everyone, hello Humdinger
Il mar 13 ott 2020, 14:40 Humdinger <dmarc-noreply@freelists.org> ha
scritto:
>
> Alternatively, you can save the below as "DesktopColor.cpp" and compile
> with:
> g++ -lbe -o DesktopColor DesktopColor.cpp
>
>
> //
> // DesktopColor prints the colour of the current workspace
> //
> #include <Application.h>
> #include <Screen.h>
>
> #include <stdio.h>
>
>
> class App : public BApplication {
> public:
> App();
> };
>
>
> App::App()
> :
> BApplication("application/x-vnd.humdinger-desktopcolor")
> {
> rgb_color color = BScreen().DesktopColor(current_workspace());
> printf("#%x%x%x\n", color.red, color.green, color.blue);
>
> PostMessage(new BMessage(B_QUIT_REQUESTED));
> }
>
> int
> main()
> {
> App app;
> app.Run();
> return 0;
> }
>
> // End
>
>
> I'm not sure if there's an even more straight forward way... but this
> works. :
>
Thanks a lot, you are very kind.
I haven't compiled it yet but I will soon.
I will continue to investigate about heying to get that value, but in the
meantime I will use your app ;).
I want to share some code with you too, that was not made by me but it's
from Andrea Anzani, aka XeD, the coder of bepodder, caya and other
BeOS/Haiku programs.
This is catindex, a cli app that dumps the values of an index, splitting it
if that has multiple values separated by commas like in META:group, or as I
do with META:keys to tag my files, with the help of this cli app I can
search them with a yab GUI.
That can be achieved with query (META:xxxx=*)|while read file do; catattr
-d META:xxxx ${file}; done | tr "," "\n", but with this app this task is
faster.
The code was taken by Haiku's People app so you don't have to worry about
the license.
Best regards,
Michele
#include <stdio.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <Query.h>
#include <Entry.h>
#include <fs_attr.h>
#include <string.h>
#include <set>
//comparison function
struct ltstr {
bool operator()(const char* s1,const char* s2) const
{
return strcmp(s1,s2) < 0 ;
}
};
void do_query(const char *);
int
main(int argc,char **argv){
if(argc<2) {
printf("usage: %s attr_name\n",argv[0]);
return 0;
}
do_query((const char*)argv[1]);
return 0;
}
void
do_query( const char *groupAttribute ) {
std::set<const char*,ltstr> myset;
BVolumeRoster volumeRoster;
BVolume volume;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
BQuery query;
query.SetVolume(&volume);
char buffer[256];
sprintf(buffer, "%s=*", groupAttribute);
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(groupAttribute, &info)
== B_OK
&& info.size > 1) {
if (info.size > sizeof(buffer))
info.size = sizeof(buffer);
if (file.ReadAttr(groupAttribute,
B_STRING_TYPE, 0, buffer, info.size) < B_OK)
continue;
const char *text = buffer;
while (true) {
char* offset = strstr(text, ",");
if (offset != NULL)
offset[0] = '\0';
char *copy = new
char[info.size];
sprintf(copy,"%s\0",text);
myset.insert(copy);
if (offset) {
text = offset + 1;
while (*text == ' ')
text++;
}
else
break;
}
}
}
}
//print results
std::set<const char*>::iterator it=myset.begin();
for(; it!=myset.end(); it++ ){
printf("%s\n",*it);
}
}
>
[Attachment #3 (text/html)]
<div dir="auto"><div>Hello everyone, hello Humdinger<br><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">Il mar 13 ott 2020, 14:40 \
Humdinger <<a href="mailto:dmarc-noreply@freelists.org" target="_blank" \
rel="noreferrer">dmarc-noreply@freelists.org</a>> ha scritto:</div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <br>
Alternatively, you can save the below as "DesktopColor.cpp" and compile \
with:<br> g++ -lbe -o DesktopColor DesktopColor.cpp<br>
<br>
<br>
//<br>
// DesktopColor prints the colour of the current workspace<br>
//<br>
#include <Application.h><br>
#include <Screen.h><br>
<br>
#include <stdio.h><br>
<br>
<br>
class App : public BApplication {<br>
public:<br>
App();<br>
};<br>
<br>
<br>
App::App()<br>
:<br>
BApplication("application/x-vnd.humdinger-desktopcolor")<br>
{<br>
rgb_color color = BScreen().DesktopColor(current_workspace());<br>
printf("#%x%x%x\n", color.red, color.green, color.blue);<br>
<br>
PostMessage(new BMessage(B_QUIT_REQUESTED));<br>
}<br>
<br>
int<br>
main()<br>
{<br>
App app;<br>
app.Run();<br>
return 0;<br>
}<br>
<br>
// End<br>
<br>
<br>
I'm not sure if there's an even more straight forward way... but this works. \
:<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Thanks a lot, \
you are very kind.</div><div dir="auto"><br></div><div dir="auto">I haven't \
compiled it yet but I will soon.</div><div dir="auto"><br></div><div dir="auto">I \
will continue to investigate about heying to get that value, but in the meantime I \
will use your app ;).</div><div dir="auto"><br></div><div dir="auto">I want to share \
<span style="font-family:sans-serif">some code</span> with you too, that was not made \
by me but it's from Andrea Anzani, aka XeD, the coder of bepodder, caya and \
other BeOS/Haiku programs.</div><div dir="auto"><br></div><div dir="auto">This is \
catindex, a cli app that dumps the values of an index, splitting it if that has \
multiple values separated by commas like in META:group, or as I do with META:keys to \
tag my files, with the help of this cli app<span style="font-family:sans-serif"> I \
can search them with a yab GUI.</span></div><div dir="auto"><br></div><div \
dir="auto">That can be achieved with query (META:xxxx=*)|while read file do; catattr \
-d META:xxxx ${file}; done | tr "," "\n", but with this app this \
task is faster.</div><div dir="auto"><br></div><div dir="auto">The code was taken by \
Haiku's People app so you don't have to worry about the license.</div><div \
dir="auto"><br></div><div dir="auto">Best regards,</div><div \
dir="auto">Michele</div><div dir="auto"><span \
style="font-family:sans-serif;font-size:12.8px"><br></span></div><div dir="auto"><div \
style="font-family:sans-serif;font-size:12.8px" dir="auto"><div \
style="width:328px;margin:16px 0px"><div>#include <stdio.h><br>#include \
<Volume.h><br>#include <VolumeRoster.h><br>#include \
<Query.h><br>#include <Entry.h><br>#include <fs_attr.h><br>#include \
<string.h><br>#include <set><br><br><br>//comparison function<br>struct \
ltstr {<br><br> bool operator()(const char* s1,const char* s2) const<br> \
{<br> return strcmp(s1,s2) < 0 ;<br> }<br>};<br><br><br>void \
do_query(const char *);<br><br><br>int<br>main(int argc,char **argv){<br><br> \
if(argc<2) {<br> printf("usage: %s \
attr_name\n",argv[0]);<br> return 0;<br> }<br><br> \
do_query((const char*)argv[1]);<br> return 0;<br>}<br><br>void<br>do_query( \
const char *groupAttribute ) {<br><br> std::set<const char*,ltstr> \
myset;<br><br> BVolumeRoster volumeRoster;<br> BVolume volume;<br> \
while (volumeRoster.GetNextVolume(&volume) == B_OK) {<br> BQuery \
query;<br> query.SetVolume(&volume);<br><br> char \
buffer[256];<br> sprintf(buffer, "%s=*", \
groupAttribute);<br> query.SetPredicate(buffer);<br> \
query.Fetch();<br><br> BEntry entry;<br> while \
(query.GetNextEntry(&entry) == B_OK) {<br> BFile \
file(&entry, B_READ_ONLY);<br> attr_info info;<br><br> \
if (file.InitCheck() == B_OK<br> && \
file.GetAttrInfo(groupAttribute, &info) == B_OK<br> \
&& info.size > 1) {<br> if (info.size > \
sizeof(buffer))<br> info.size = \
sizeof(buffer);<br><br> if \
(file.ReadAttr(groupAttribute, B_STRING_TYPE, 0, buffer, info.size) < B_OK)<br> \
continue;<br><br> const char *text = buffer;<br> \
while (true) {<br> char* offset = strstr(text, \
",");<br> if (offset != NULL)<br> \
offset[0] = '\0';<br> char \
*copy = new char[info.size];<br> \
sprintf(copy,"%s\0",text);<br><br> \
myset.insert(copy);<br><br> if (offset) {<br> \
text = offset + 1;<br> while (*text == \
' ')<br> text++;<br> \
}<br> else<br> \
break;<br> }<br> }<br> \
}<br> }<br><br> //print results<br> std::set<const \
char*>::iterator it=myset.begin(); <br> for(; it!=myset.end(); it++ \
){<br> printf("%s\n",*it);<br> \
}<br><br>}</div></div></div></div><div dir="auto"><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic