[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 &lt;<a href="mailto:dmarc-noreply@freelists.org" target="_blank" \
rel="noreferrer">dmarc-noreply@freelists.org</a>&gt; 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 &quot;DesktopColor.cpp&quot; 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 &lt;Application.h&gt;<br>
#include &lt;Screen.h&gt;<br>
<br>
#include &lt;stdio.h&gt;<br>
<br>
<br>
class App : public BApplication {<br>
public:<br>
        App();<br>
};<br>
<br>
<br>
App::App()<br>
        :<br>
        BApplication(&quot;application/x-vnd.humdinger-desktopcolor&quot;)<br>
{<br>
        rgb_color color = BScreen().DesktopColor(current_workspace());<br>
        printf(&quot;#%x%x%x\n&quot;, 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&#39;m not sure if there&#39;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&#39;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&#39;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 &quot;,&quot; &quot;\n&quot;, but with this app this \
task is faster.</div><div dir="auto"><br></div><div dir="auto">The code was taken by \
Haiku&#39;s People app so you don&#39;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 &lt;stdio.h&gt;<br>#include \
&lt;Volume.h&gt;<br>#include &lt;VolumeRoster.h&gt;<br>#include \
&lt;Query.h&gt;<br>#include &lt;Entry.h&gt;<br>#include &lt;fs_attr.h&gt;<br>#include \
&lt;string.h&gt;<br>#include &lt;set&gt;<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) &lt; 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&lt;2) {<br>                printf(&quot;usage: %s \
attr_name\n&quot;,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&lt;const char*,ltstr&gt; \
myset;<br><br>        BVolumeRoster volumeRoster;<br>        BVolume volume;<br>      \
while (volumeRoster.GetNextVolume(&amp;volume) == B_OK) {<br>                BQuery \
query;<br>                query.SetVolume(&amp;volume);<br><br>                char \
buffer[256];<br>                sprintf(buffer, &quot;%s=*&quot;, \
groupAttribute);<br>                query.SetPredicate(buffer);<br>                \
query.Fetch();<br><br>                BEntry entry;<br>                while \
(query.GetNextEntry(&amp;entry) == B_OK) {<br>                        BFile \
file(&amp;entry, B_READ_ONLY);<br>                        attr_info info;<br><br>     \
if (file.InitCheck() == B_OK<br>                                &amp;&amp; \
file.GetAttrInfo(groupAttribute, &amp;info) == B_OK<br>                               \
&amp;&amp; info.size &gt; 1) {<br>                                if (info.size &gt; \
sizeof(buffer))<br>                                        info.size = \
sizeof(buffer);<br><br>                                if \
(file.ReadAttr(groupAttribute, B_STRING_TYPE, 0, buffer, info.size) &lt; B_OK)<br>    \
continue;<br><br>                                const char *text = buffer;<br>       \
while (true) {<br>                                        char* offset = strstr(text, \
&quot;,&quot;);<br>                                        if (offset != NULL)<br>    \
offset[0] = &#39;\0&#39;;<br>                                                char \
*copy = new char[info.size];<br>                                                \
sprintf(copy,&quot;%s\0&quot;,text);<br><br>                                          \
myset.insert(copy);<br><br>                                        if (offset) {<br>  \
text = offset + 1;<br>                                                while (*text == \
&#39; &#39;)<br>                                                        text++;<br>   \
}<br>                                        else<br>                                 \
break;<br>                                }<br>                        }<br>          \
}<br>        }<br><br>        //print results<br>        std::set&lt;const \
char*&gt;::iterator it=myset.begin();       <br>        for(; it!=myset.end(); it++ \
){<br>                printf(&quot;%s\n&quot;,*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