Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » More new functions
More new functions [message #18804] Wed, 22 October 2008 23:25 Go to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

I propose you some new functions tested in GNU/Linux Ubuntu (Gnome), XP and Vista.
Please give me your feedback and feel free to fix everything:

String GetExtExecutable(const char *ext);

// GetExtExecutable("pdf") will return the name of the program
// that by default open pdf files.
// In XP/Vista it will return the program with the full path


bool LaunchFile(const String& file);

// LaunchFile("Sheet.xls") will open the file with the
// program asigned by default to open xls files


int LaunchCommand(const char *cmd, void (*readCallBack)(String &));

// LaunchCommand("mplayer myclip.avi", MyCallback) will launch
// the command line program with args without opening a window, and
// all the output will be sent to MyCallback(String &) function


int LaunchCommand(const char *cmd, String &ret);

// LaunchCommand("mplayer myclip.avi",str) will do the same
// but sending the output to String str


String GetDesktopFolder();
String GetProgramsFolder();
String GetAppDataFolder();
String GetMusicFolder();
String GetPicturesFolder();
String GetVideoFolder();
String GetPersonalFolder();
String GetTemplatesFolder();
String GetDownloadFolder();

// These functions return the folder assigned for Desktop,
// Program Files, etc.
// (from now please do not do this:
// AppendFileName(GetHomeFolder(), "Desktop");
// to refer to the Desktop folder or using
// "C:\\Program Files" ...
// in many languages is wrong
// It does not handle firefox download folder as it has been
// impossible for me to know where it is (until now)


bool FileCat(const char *file, const char *appendFile);

// FileCat("FirstFile", "SecondFile") just append SecondFile
// from the end of FirstFile


As you may see some of them use in Linux Portland XdgUtils in the background.
I think it is a strong portable widespread source of information.

If somebody is interested I have a small class that works like
LaunchCommand but opening a command window that handles \r and
\n properly (to be used for example with mencoder).


Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #18808 is a reply to message #18804] Thu, 23 October 2008 07:35 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Interesting functions!
Thanks!
Re: More new functions [message #18815 is a reply to message #18804] Fri, 24 October 2008 01:22 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
These are great; really good functionality. Are they being added to core? or maybe we can add them as a utility package in bazar if not.
Re: More new functions [message #18817 is a reply to message #18804] Fri, 24 October 2008 08:11 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Thank you. About how to integrate them in Upp is a matter to be decided by the main developers.

Just to say that I have ready to post in few days a new version that supports firefox (if firefox is the by default web browser, GetDownloadFolder() returns the folder where the downloads go by default).

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #18819 is a reply to message #18817] Fri, 24 October 2008 14:05 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Can you explain this line to me?
int LaunchCommand(const char *cmd, void (*readCallBack)(String &))
Particularly the readCallBack part.

Also, if you're not using a GUI (CtrlCore), what will happen with this line:
Ctrl::ProcessEvents();
Re: More new functions [message #18821 is a reply to message #18819] Fri, 24 October 2008 15:28 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
captainc wrote on Fri, 24 October 2008 13:05

Can you explain this line to me?
int LaunchCommand(const char *cmd, void (*readCallBack)(String &))
Particularly the readCallBack part.

Shouldn't this be:
int LaunchCommand(const char *cmd, Callback1<String> readCallBack)


captainc wrote on Fri, 24 October 2008 13:05

Also, if you're not using a GUI (CtrlCore), what will happen with this line:
Ctrl::ProcessEvents();


I haven't tried, but presumably it won't compile. I'm also not sure if it's safe to call ProcessEvents from outside the GUI thread, but I'm guessing not.

Perhaps you could replace ProcessEvents with Sleep? If somebody wants to update a GUI then they should use the Callback version of LaunchCommand and do it themselves. I think it could then be run in a thread, which would be more useful for command line apps IMO.

[Updated on: Fri, 24 October 2008 15:44]

Report message to a moderator

Re: More new functions [message #18834 is a reply to message #18804] Sun, 26 October 2008 01:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

Thank you for the feedback. First I inclose you a screengrab of a program I am doing that uses these functions. It is very preliminary but it runs:

index.php?t=getfile&id=1462&private=0

With this program I drag-drop movie clips in a main track that I convert in DVD format mpg files:
- With LaunchCommand(const char *cmd, String &ret); I get the video images you see in the center-left side column using mplayer
- With LaunchCommand(const char *cmd, void (*readCallBack)(String &)); I get the final .mpg DVD compatible file using mencoder. All the mencoder output goes to a function that sends it to a window (in the screengrab). If the window is closed, it kills the process before.

Coming to the comments:
- You are right: I have to change LaunchCommand in case of non GUI program to not call Ctrl::ProcessEvents();
- Ctrl::ProcessEvents(); lets the main GUI program to follow doing other things and being responsive to user without stoping the process. The command runs in another thread and the main GUI program only gets its output.
It is not perfect multithread, but it works well.
- In LaunchCommand, for example, to join to files, I would do LaunchCommand("mencoder a.avi b.avo -oac copy -ovc copy - ab.avi", myfun);
a basic myfun would be like:
void myfun(String &s)
{
     MySendStrToCommandWindow(s);
     MyParseStrToMoveProgressBar(s);
}

About the functions, I have prepared more but before finishing them I would like to ask you if putting them in different functions or declaring them into classes like:

class SysFolders          // Special folders
	String GetDesktop();
	String GetPrograms();
	String GetAppData();
	String GetMusic();
	String GetPictures();
	String GetVideo();
	String GetPersonal();
	String GetTemplates();
	String GetDownload();

	String GetRoot();  // New
	String GetTemp();  // New
        Possible new functions to change folders

class SysOS          // OS info. Samples after //
	String GetName();	// Windows  Linux
	String GetCode();	// 6.0	    2.6.8-1.523
	String GetVersion();	// Vista    Ubuntu
	String GetRelease();	// Home Premium Edition	8.04
	String GetSize();	// 64-bit   32-bit

class SysCPU          //CPU info
	String GetIdentifier();
	String GetLevel();
	String GetRevision();
	String GetArchitecture;
	String GetSpeed();
	String GetNumber();
        Possible new functions to get more details

class SysProcesses          //Current processes info. 
	bool Update();      // Gets processes info
	bool GetFirst(int processId, String pName);
	vool GetNext(int processId, String pName);
        Possible new functions to kill processes or change priority


I have seen in Upp that it tends to not create new classes with grouped static functions inside, but doing alone functions. What do you prefer ?

Best regards
Koldo



Best regards
Iñaki
Re: More new functions [message #18835 is a reply to message #18834] Sun, 26 October 2008 02:03 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Quote:

I have seen in Upp that it tends to not create new classes with grouped static functions inside, but doing alone functions.

This is a good point. I think it would be helpful to have functions grouped in some way. I have learned about the global function by just going one by one down the auto-complete assist++ list and reading the code on what those functions do. Some are self-explanatory, others are not. Most of them have simple intuitive names, but sometimes you need to do a search through all the functions to find the one you are looking for because assist++ matches from the beginning of the name. Though, in some ways, all those global functions have been very helpful because they were right there for me to scroll to. I think the problem is going to come in as we keep adding more and more to global.

[Updated on: Sun, 26 October 2008 02:04]

Report message to a moderator

Re: More new functions [message #18840 is a reply to message #18804] Sun, 26 October 2008 10:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello captainc

Thats it. In some cases is more than grouping functions indeed.
For example in the "SysCPU" functions related with the CPU info, the program gets all the information in one time so, for String GetSpeed() it will get all information for just getting the speed. As this information does not change while the program is running (CPU make, number, speed, etc), the class would gather all the info one time so the function would be like this:

SysCPU::GetSpeed() {return speed;};

In "SysProcesses" functions it is a little different as the processes info is something changing so we could have at the same cost two focus:
- class SysProcesses //Current processes info.
bool Update(); // Gets processes info
bool GetFirst(int &processId, String &pName);
vool GetNext(int &processId, String &pName);

or
- bool GetProcessesList(Array<int>&pid, Array<String>&name);

Best regards
Koldo

(P.D. Class and function names are just a proposal that you could change)


Best regards
Iñaki

[Updated on: Sun, 26 October 2008 10:20]

Report message to a moderator

Re: More new functions [message #18880 is a reply to message #18804] Thu, 30 October 2008 08:24 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

Sorry for the delay. Now I am waiting for luzr final feedback about the structure of these functions.

After that I plan to have them ready (functions, a guy test and a text test) and tested for XP, Vista, Ubuntu 32 and 64 bits in two weeks.

In the second phase of about a month I want to test them with these free (as free beer) distros: Mandriva, Open Suse, Gentoo and Knoppix, 32/64 bits, Intel/AMD64, Gnome/Kde/Xfce desktops.
This is because some of these functions have to identify the system accurately so they have to be tested with as many systems as possible.

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #18902 is a reply to message #18804] Fri, 31 October 2008 10:44 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
I have a little question.

We are always speaking about xp, vista ubuntu 32 & 64 but what about xp and vista 64 ?
Does upp works well on these paltforms ?
Re: More new functions [message #18903 is a reply to message #18804] Fri, 31 October 2008 13:25 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello cocob

Sorry but I cannot answer you as I do not have access to them.

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #18904 is a reply to message #18880] Fri, 31 October 2008 13:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Thu, 30 October 2008 03:24

Hello all

Sorry for the delay. Now I am waiting for luzr final feedback about the structure of these functions.



class SysFolders          // Special folders
	String GetDesktop();
	String GetPrograms();
	String GetAppData();
	String GetMusic();
	String GetPictures();
	String GetVideo();
	String GetPersonal();
	String GetTemplates();
	String GetDownload();

	String GetRoot();  // New
	String GetTemp();  // New
        Possible new functions to change folders


I think these should be in App.h, as global functions appended with "Path" or "Folder".

class SysOS          // OS info. Samples after //
	String GetName();	// Windows  Linux


I am not quite sure the merit of above.

	String GetCode();	// 6.0	    2.6.8-1.523


IMO we need something more comparable there. Maybe like puttint it into int64 as 4 16-bit fields or something like that? Or maybe just introduce "CompareVersion" function?

CompareVersion("2.4.5", "2.5.2") < 0

	String GetSize();	// 64-bit   32-bit


What for?

class SysCPU          //CPU info
	String GetIdentifier();
	String GetLevel();
	String GetRevision();
	String GetArchitecture;
	String GetSpeed();
	String GetNumber();
        Possible new functions to get more details


Well, maybe... Anyway, I have a hard time imagining what are these good for beyond some fancy about box.

Still, not a bad idea to have it implemented.

class SysProcesses          //Current processes info. 
	bool Update();      // Gets processes info
	bool GetFirst(int processId, String pName);
	vool GetNext(int processId, String pName);
        Possible new functions to kill processes or change priority


Yes, class for this one... The question is whether this belongs to Core. Most apps will not need this. But perhaps yes still.

Mirek
Re: More new functions [message #18916 is a reply to message #18804] Fri, 31 October 2008 15:51 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello luzr

I agree. I begin to work.

About SysOS and SysCPU:
-
String GetName();	// Windows  Linux
Well... touché!

- I agree with your code:
CompareVersion("2.4.5", "2.5.2") < 0

- I will also include distro identification

Somebody could say that the user do know the OS, desktop, distro, cpu, etc. as it is his/her computer. But:
- Some info is interesting for the program itself, as knowing which desktop is installed
- In case of errors the program can do accurate reports to be sent to the developers.

But for SysCPU, I will reduce the number of functions...

I will also include this functions:

// I do not like this name. Perhaps:
// GetExtProgram() or GetProgramFromExtension()
String GetExtExecutable(const char *ext);
bool LaunchFile(const String& file);

int LaunchCommand(const char *cmd, void (*readCallBack)(String &));
int LaunchCommand(const char *cmd, String &ret);

bool FileCat(const char *file, const char *appendFile);

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #18917 is a reply to message #18916] Fri, 31 October 2008 16:03 Go to previous messageGo to next message
bytefield is currently offline  bytefield
Messages: 210
Registered: December 2007
Experienced Member
Instead of having these functions parted or just some of them i suggest to make a Sys package on bazaar and put in it all stuff that is related to, so who want to use CPU/OS/Version/etc may use that package easy and who doesn't need these functions doesn't have to worry about "bloating" his code... I think that's why Upp have a modular design, no? And that's why bazaar exist...

cdabbd745f1234c2751ee1f932d1dd75
Re: More new functions [message #19117 is a reply to message #18804] Thu, 13 November 2008 09:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

I follow working hard in this.
Now It is 100% tested in Windows and 80% in Linux.
I expect to show you the results in few days.

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #19193 is a reply to message #19117] Wed, 19 November 2008 08:09 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello all

I will post tomorrow the functions tested in XP and Vista (MinGW and MSC), Ubuntu 32-64 8.04, Kubuntu and Xfce 8.10 and Fedora 9.

Best regards
Koldo


Best regards
Iñaki
Re: More new functions [message #19200 is a reply to message #18804] Wed, 19 November 2008 17:44 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Here it is!

I enclose you two folders:
- SysInfo: The package
---- SysInfo.cpp
---- SysInfo.h
---- SysInfo.upp
- SysInfo demo non-gui: A command line sample
---- main.cpp: The sample
---- SysInfo demo non-gui.upp

Finally I have included much more functions. Just run the demo program and play with it.

There are "SysInfo" functions and others, mainly because they were necessary. Please tell me the best way to organize them to be enclosed some in bazaar and some in other packages.

The next steps will be in addition to do a gui demo and to test the commands in more distros and OS as FreeBSD, OpenSolaris, Slackware and Knoppix. And of course to fix bugs and include more things if you want.

Best regards
Koldo

PD. I enclose you part of the program output as a sample:


Introduce enter or (l) to log off, (r) to reboot or (s) to shutdown
Introduce number of test cycles or just type enter to run it once:
SysInfo functions demo

Special folders
Desktop: /home/aupa/Escritorio
Programs: /usr/bin
Application Data: /home/aupa
Music: /home/aupa/Escritorio
Pictures: /home/aupa/Escritorio
Video: /home/aupa/Escritorio
Personal: /home/aupa/Escritorio
Templates: /home/aupa/Escritorio
Download: /home/aupa/Escritorio
Temp: /home/aupa
Os: /bin
System:

System info:
System manufacturer 'TOSHIBA', product name 'Satellite A300',
version 'PSWJ0E-21403CE', number of processors: 2
Real CPU Speed: 1.830 GHz
Battery info
Working with battery: yes, Percentage: 85%, Remaining; 151 min
Bios version 'V2.70 ',
release date '04/14/2008'
Processor #0: Vendor 'GenuineIntel',
identifier 'Intel(R) Core(TM)2 Duo CPU T5550 @ 1.83GHz',
architecture 'i686
Family 6 Model 15 Stepping 13', speed 1833 MHz
Processor #1: Vendor 'GenuineIntel',
identifier 'Intel(R) Core(TM)2 Duo CPU T5550 @ 1.83GHz',
architecture 'i686
Family 6 Model 15 Stepping 13', speed 1833 MHz

Press enter to continue...

Memory info:
Percent of memory in use: 75%
Total physical memory: 2116001792 bytes (2.0Gb)
Free physical memory: 518352896 bytes (494.3Mb)
Total paging file: 729112576 bytes (695.3Mb)
Free paging file: 0 bytes (0b)
Total virtual memory: 4721266688 bytes (4.4Gb)
Free virtual memory: 4721266688 bytes (4.4Gb)

Os info:
Kernel: Linux, version: 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008,
architecture: i686

Distro: ubuntu, version: 8.04
Desktop: gnome, version: 2.22.3

Program compiled with gnuc version 40103. Compilation date: Nov 19 2008

Default exes info:
Default program for 'html' is 'firefox.desktop'
Default program for 'doc' is 'ooo-writer.desktop'
Default program for 'png' is 'eog.desktop'
Default program for 'pdf' is 'evince.desktop'
Default program for 'txt' is 'gedit.desktop'
Default program for 'xyz' is ''

Drives list:
Drive path:'/'
Type: 'Hard', Volume: 'Linux',
MaxName: 255, File System: ext3
Free Bytes User: 46895562752 (43.7Gb)
Total Bytes User: 54519554048 (50.8Gb), Total Free Bytes: 46895562752 (43.7Gb)
Drive path:'/home'
Type: 'Hard', Volume: 'Shared drive',
MaxName: 255, File System: ext3
Free Bytes User: 71834021888 (66.9Gb)
Total Bytes User: 130094362624 (121.2Gb), Total Free Bytes: 71834021888 (66.9Gb)

Other Info:
Process Id: 17248
Process name: 'demo'
Process file name: '/home/exe/demo'
Process priority is: 5
Now changed to high priority: No
Process priority is: 5

Launch file 'test.txt':

If modify 'test.txt' it will ask you to save or not the file
If you answer Yes or No the program will be terminated
If you answer Cancel or wait more than 5 seconds the program will be killed

Press enter to terminate 'test.txt'
Process terminated

Windows list:
Window hwnd: 41943086, processId: 6154, Name: gdesklets-daemon
File name: /usr/bin/python2.5
Window caption: 'gdesklets-daemon '
Window hwnd: 16821977, processId: 5995, Name: nautilus
File name: /usr/bin/nautilus
Window caption: 'SysInfo demo non-gui - Navegador de archivos '
Window hwnd: 35654762, processId: 0, Name: theide-svn
File name:
Window caption: 'SysInfo demo non-gui - - TheIDE - [/home/SysInfo/SysInfo.cpp UTF-8] { MyApps } '

Process list:
Id 5898: Priority: 5, Program: /usr/bin/gnome-session
Id 5948: Priority: 5, Program: /usr/lib/libgconf2-4/gconfd-2
Id 5956: Priority: 5, Program: /usr/bin/seahorse-agent
Id 17071: Priority: 5, Program: /usr/bin/theide-svn
  • Attachment: SysInfo.7z
    (Size: 17.96KB, Downloaded 325 times)


Best regards
Iñaki
Re: More new functions [message #19204 is a reply to message #19200] Thu, 20 November 2008 10:35 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Quote:

C:\MyApps\SysInfo\SysInfo.cpp(30) : fatal error C1083: Cannot open include file: 'usvn/SlaveProcess.cpp': No such file or directory
Re: More new functions [message #19210 is a reply to message #18804] Thu, 20 November 2008 14:18 Go to previous messageGo to previous message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Hello Ion

Look to your upp/uppsrc folder. Inside there has to be a usvn folder with SlaveProcess.cpp file inside.

If not try to look for that file and include it in the project.

Please tell if you found it and where for fixing if something is wrong from me.

Best regards
Koldo


Best regards
Iñaki
Previous Topic: Simple app-wide "macros"
Next Topic: Grid helper
Goto Forum:
  


Current Time: Tue Apr 23 08:51:31 CEST 2024

Total time taken to generate the page: 0.02254 seconds