Page 1 of 1

HOW TO: put files in blob and after that, open them!

PostPosted: Wed Dec 24, 2003 2:58 pm
by Harjo
Hi all, here is a HOW TO: put files in blob and after that, open them right away

BTW this is only working in 2.0beta5

make 4 fields:
bestandspad TEXT 200
bestandsnaam TEXT 50
bestandgrootte INTEGER
media (IMAGEMEDIA)


To put files in the blob an fill the appropriate fields do this:
Code: Select all
controller.newRecord()
filename = application.showFileOpenDialog();
if (filename)//for cancel
{
   var normalizedFileName = "";
   normalizedFileName = utils.stringReplace(filename,'\\','/')//make windows path like unix path
   bestandspad = normalizedFileName

   var idx = normalizedFileName.lastIndexOf("/");
   if (idx != -1) normalizedFileName = normalizedFileName.substring(idx+1 );
   bestandsnaam = normalizedFileName
   media = application.readFile(filename)
   bestandgrootte = plugins.file.getFileSize(filename)
}


after that, make a method that opens the files right away from out the database:

Code: Select all
var a = bestandsnaam.lastIndexOf(".")
var b = bestandsnaam.substr(0,a)
var c = bestandsnaam.substring(a)

var filename = application.createTempFile(b,c)
application.writeFile(filename,media);

if(utils.stringMiddle(application.getOSName(),1,7) == "Windows")
{
   application.executeProgramInBackground('rundll32', 'url.dll,FileProtocolHandler',filename)
}


Mabey someone can make the last method compatible with Macintosh or Linux/Unix.

PostPosted: Mon Dec 29, 2003 5:13 pm
by david
Tack this onto the end for Mac:

Code: Select all
else
{
if (utils.stringLeftWords(application.getOSName(), 1) == "Mac")
{
   application.executeProgram('open', filename);
}
}


- david

PostPosted: Mon Dec 29, 2003 5:31 pm
by Bert
david wrote:Tack this onto the end for Mac:


Thank You, David :D

Linux: open with default app

PostPosted: Fri Aug 27, 2004 3:45 pm
by Riccardino
david wrote:Tack this onto the end for Mac:

Code: Select all
else
{
if (utils.stringLeftWords(application.getOSName(), 1) == "Mac")
{
   application.executeProgram('open', filename);
}
}


- david


Does anybody has an idea to how make a similar code to work under Linux? I tried to use the open command, but it seems to have no effect (even if I try to use it from a terminal window).

PostPosted: Fri Sep 03, 2004 2:24 pm
by sebster
Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they've answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk

PostPosted: Wed Sep 08, 2004 2:46 pm
by Riccardino
sebster wrote:Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they've answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk


Thanks, Sebastian

I'll set Mozilla as default (it seems to be the most common app, present in almost all distributions).

:-)

PostPosted: Sat Sep 11, 2004 11:06 am
by Riccardino
sebster wrote:Best thing to do is ask them what application they want to open the file, and possibly substitute %s with the filename. Once they've answered this question once, remember it.

For example, on my unix install, images could be displayed with a variety of programs:

gimp %s
mozilla %s
firefox %s
xv %s
display %s

Personally I prefer xv or mozilla. Others prefer firefox.

Also you can do all kinds of options this way, for example:

myprogram --filename %s --myotheroption someothervalue

Sebastiaan van Erk

[/quote]

I tried with several combinations, but I've only been able to make this one work:
application.executeProgram('mozilla', tmpfile);

But, this way, Mozilla must be closed in order to come back to Servoy.
Is it possible to make Mozilla act as a non-modal window?