Example #1
0
 String windowsStylePath (const String& path)    { return path.replaceCharacter ('/', '\\'); }
Example #2
0
 String unixStylePath (const String& path)       { return path.replaceCharacter ('\\', '/'); }
Example #3
0
void UploadWindow::filesDropped(const StringArray& filenames, int mouseX, int mouseY)
{
	StringArray extensions;
	extensions.addTokens(".jpg;.jpeg;.jpe;.png;.tif;.tiff;.png;.gif;.mpg;.mpeg;.mpe;.mov;.qt;.avi;.wmv", ";", "");

	UploadRequest* ur = new UploadRequest();
	for (int i = 0; i < filenames.size(); i++)
	{
		File imageFile(File::getCurrentWorkingDirectory().getChildFile (filenames[i]));
        
		if (imageFile.existsAsFile() && extensions.contains(imageFile.getFileExtension(), true))
		{
			ur->addImageFile(imageFile);
		}
		else if (imageFile.isDirectory())
		{
			Array<File> results;			
			imageFile.findChildFiles(results, File::findFiles, true);

			for (int i = 0; i < results.size(); i++)
			{
				if (extensions.contains(results[i].getFileExtension(), true))
					ur->addImageFile(results[i]);
			}
		}
	}

	if (ur->getNumImages() > 0)
	{
		Settings* settings = Settings::getInstance();
		if (settings->password.isEmpty() || settings->email.isEmpty())
			settings->showSettingsDialog();

		if (settings->password.isEmpty() || settings->email.isEmpty())
			return;

		if (!smugMug.isLoggedIn())
			smugMug.login(Settings::getInstance()->email, Settings::getInstance()->password);

		if (!smugMug.isLoggedIn())
		{
			AlertWindow::showMessageBox(AlertWindow::WarningIcon, "Komodo Drop", "Error: Unable to connect to Smugmug.");
			return;
		}

		String defaultAlbumName;
		File root(filenames[0]);
		if (filenames.size() == 1 && root.isDirectory())
			defaultAlbumName = root.getFileName();
		else 
			defaultAlbumName = root.getParentDirectory().getFileName();

#ifdef JUCE_DEBUG
		defaultAlbumName = defaultAlbumName.replaceCharacter('_', ' ');
#endif

		SmugID albumId;
		bool open = false;
		if (Settings::getInstance()->silentUpload)
		{
			OwnedArray<Album> albums;
			smugMug.getAlbumList(albums);
			
			for (int i = 0; i < albums.size(); i++)
			{
				if (albums[i]->title == defaultAlbumName)
				{
					albumId = albums[i]->id;
					break;
				}
			}
			if (albumId.id == -1)
			{
				StringPairArray params;
				albumId = smugMug.createAlbum(defaultAlbumName, 0, params);
			}
			ur->setName(defaultAlbumName);
		}
		else
		{
			bool newAlbum;
			int catId;
			String title;
			StringPairArray params;

			UploadDialog* ud = new UploadDialog(&smugMug, defaultAlbumName, newAlbum, title, albumId, catId, params, open);
			if (ud->runModalLoop() == 1)
			{
				ur->setName(title);
				if (newAlbum)
					albumId = smugMug.createAlbum(title, catId, params);
			}
			else
			{
				return;
			}
		}

		if (albumId.id != -1)
		{
			ur->setOpenBrowser(open);
			ur->setAlbumId(albumId);
			smugMug.uploadImages(ur);
			startTimer(333);
			repaint();
		}
		else
		{
			delete ur;
		}
	}
	else
	{
		delete ur;
	}
	return;
}
Example #4
0
//==============================================================================
String File::parseAbsolutePath (const String& p)
{
    if (p.isEmpty())
        return String::empty;

#if JUCE_WINDOWS
    // Windows..
    String path (p.replaceCharacter ('/', '\\'));

    if (path.startsWithChar (separator))
    {
        if (path[1] != separator)
        {
            /*  When you supply a raw string to the File object constructor, it must be an absolute path.
                If you're trying to parse a string that may be either a relative path or an absolute path,
                you MUST provide a context against which the partial path can be evaluated - you can do
                this by simply using File::getChildFile() instead of the File constructor. E.g. saying
                "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
                path if that's what was supplied, or would evaluate a partial path relative to the CWD.
            */
            jassertfalse;

            path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
        }
    }
    else if (! path.containsChar (':'))
    {
        /*  When you supply a raw string to the File object constructor, it must be an absolute path.
            If you're trying to parse a string that may be either a relative path or an absolute path,
            you MUST provide a context against which the partial path can be evaluated - you can do
            this by simply using File::getChildFile() instead of the File constructor. E.g. saying
            "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
            path if that's what was supplied, or would evaluate a partial path relative to the CWD.
        */
        jassertfalse;

        return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
    }
#else
    // Mac or Linux..

    // Yes, I know it's legal for a unix pathname to contain a backslash, but this assertion is here
    // to catch anyone who's trying to run code that was written on Windows with hard-coded path names.
    // If that's why you've ended up here, use File::getChildFile() to build your paths instead.
    jassert ((! p.containsChar ('\\')) || (p.indexOfChar ('/') >= 0 && p.indexOfChar ('/') < p.indexOfChar ('\\')));

    String path (p);

    if (path.startsWithChar ('~'))
    {
        if (path[1] == separator || path[1] == 0)
        {
            // expand a name of the form "~/abc"
            path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
                    + path.substring (1);
        }
        else
        {
            // expand a name of type "~dave/abc"
            const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));

            if (struct passwd* const pw = getpwnam (userName.toUTF8()))
                path = addTrailingSeparator (pw->pw_dir) + path.fromFirstOccurrenceOf ("/", false, false);
        }
    }
    else if (! path.startsWithChar (separator))
    {
       #if JUCE_DEBUG || JUCE_LOG_ASSERTIONS
        if (! (path.startsWith ("./") || path.startsWith ("../")))
        {
            /*  When you supply a raw string to the File object constructor, it must be an absolute path.
                If you're trying to parse a string that may be either a relative path or an absolute path,
                you MUST provide a context against which the partial path can be evaluated - you can do
                this by simply using File::getChildFile() instead of the File constructor. E.g. saying
                "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
                path if that's what was supplied, or would evaluate a partial path relative to the CWD.
            */
            jassertfalse;

           #if JUCE_LOG_ASSERTIONS
            Logger::writeToLog ("Illegal absolute path: " + path);
           #endif
        }
       #endif

        return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
    }
#endif

    while (path.endsWithChar (separator) && path != separatorString) // careful not to turn a single "/" into an empty string.
        path = path.dropLastCharacters (1);

    return path;
}
void FileChooser::showPlatformDialog (Array<File>& results,
                                      const String& title,
                                      const File& file,
                                      const String& filters,
                                      bool isDirectory,
                                      bool /* selectsFiles */,
                                      bool isSave,
                                      bool /* warnAboutOverwritingExistingFiles */,
                                      bool selectMultipleFiles,
                                      FilePreviewComponent* /* previewComponent */)
{
    String separator;
    StringArray args;

    const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
    const bool isKdeFullSession = SystemStats::getEnvironmentVariable ("KDE_FULL_SESSION", String::empty)
                                    .equalsIgnoreCase ("true");

    if (exeIsAvailable ("kdialog") && (isKdeFullSession || ! exeIsAvailable ("zenity")))
    {
        // use kdialog for KDE sessions or if zenity is missing
        args.add ("kdialog");

        if (title.isNotEmpty())
            args.add ("--title=" + title);

        if (selectMultipleFiles)
        {
            separator = "\n";
            args.add ("--multiple");
            args.add ("--separate-output");
            args.add ("--getopenfilename");
        }
        else
        {
            if (isSave)             args.add ("--getsavefilename");
            else if (isDirectory)   args.add ("--getexistingdirectory");
            else                    args.add ("--getopenfilename");
        }

        String startPath;

        if (file.exists())
        {
            startPath = file.getFullPathName();
        }
        else if (file.getParentDirectory().exists())
        {
            startPath = file.getParentDirectory().getFullPathName();
        }
        else
        {
            startPath = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();

            if (isSave)
                startPath += "/" + file.getFileName();
        }

        args.add (startPath);
        args.add (filters.replaceCharacter (';', ' '));
        args.add ("2>/dev/null");
    }
    else
    {
        // zenity
        args.add ("zenity");
        args.add ("--file-selection");

        if (title.isNotEmpty())
            args.add ("--title=" + title);

        if (selectMultipleFiles)
        {
            separator = ":";
            args.add ("--multiple");
            args.add ("--separator=" + separator);
        }
        else
        {
            if (isDirectory)  args.add ("--directory");
            if (isSave)       args.add ("--save");
        }

        if (file.isDirectory())
            file.setAsCurrentWorkingDirectory();
        else if (file.getParentDirectory().exists())
            file.getParentDirectory().setAsCurrentWorkingDirectory();
        else
            File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory();

        if (! file.getFileName().isEmpty())
            args.add ("--filename=" + file.getFileName());
    }

    ChildProcess child;

    if (child.start (args, ChildProcess::wantStdOut))
    {
        const String result (child.readAllProcessOutput().trim());

        if (result.isNotEmpty())
        {
            StringArray tokens;

            if (selectMultipleFiles)
                tokens.addTokens (result, separator, "\"");
            else
                tokens.add (result);

            for (int i = 0; i < tokens.size(); ++i)
                results.add (File::getCurrentWorkingDirectory().getChildFile (tokens[i]));
        }

        child.waitForProcessToFinish (60 * 1000);
    }

    previousWorkingDirectory.setAsCurrentWorkingDirectory();
}