void KSubtitleRipperView::createSRT() {
	// TODO check if srttool is executable
	
	if ( !askIfModified() ) return;

	KURL url = KFileDialog::getSaveURL( srtName, "*.srt|" + i18n("SRT Subtitles"), this, i18n( "Save Subtitles" ) );
	if ( url.isEmpty() || !url.isValid() ) return;
	
	/*QString extension = QFileInfo( url.path() ).extension( false ).lower();
	if ( extension != "srt" && ( !url.isLocalFile() || !QFile::exists( url.path() ) ) )
		url = url.url() + ".srt";
	*/
	QString text = "A file named \"%1\" already exists.\nAre you sure you want to overwrite it?";
	if ( url.isLocalFile() && QFile::exists( url.path() ) &&
		KMessageBox::warningContinueCancel( this, i18n( text ).arg( url.filename() ),
		i18n( "Overwrite File?" ), i18n( "Overwrite" ) ) == KMessageBox::Cancel ) return;
	
	newSrt = new KURL( url );
	
	if ( url.isLocalFile() ) {
		tmpSrt = QString::null;
		
		CreateSRT *createSrt = new CreateSRT( project, url.path() );
		
		connect(createSrt, SIGNAL(success( CreateSRT* )),
			this, SLOT(createSrtSuccess( CreateSRT* ) ) );
		connect(createSrt, SIGNAL(failed( CreateSRT*, const QString& )),
			this, SLOT(createSrtFailed( CreateSRT*, const QString& ) ) );
		
		createSrt->saveSRT();
	} else {
void RulesDialog::slotUser2()
{
  KURL kurl = KFileDialog::getSaveURL(0, i18n("*.sh|Shell Scripts (*.sh)"), this);
  if (kurl.path() == "")
    return;

  KTempFile temp;
  QString fileName = kurl.path();

  if (fileName == "")
    return;

  if (!kurl.isLocalFile())
  {
    fileName = temp.name();
  }
  
  QFile file(fileName);
  file.open(IO_WriteOnly);
  QTextStream stream(&file);
  stream << mRules->text();
  file.close();
  if (!kurl.isLocalFile())
  {
    if (!KIO::NetAccess::upload(fileName, kurl, this))
      KMessageBox::error(this, i18n("Failed to upload file."));
  }

  temp.unlink();
}
Example #3
0
void KFileItem::setUDSEntry( const KIO::UDSEntry& _entry, const KURL& _url,
    bool _determineMimeTypeOnDemand, bool _urlIsDirectory )
{
  m_entry = _entry;
  m_url = _url;
  m_strName = QString::null;
  m_strText = QString::null;
  m_user = QString::null;
  m_group = QString::null;
  m_strLowerCaseName = QString::null;
  m_pMimeType = 0;
  m_fileMode = KFileItem::Unknown;
  m_permissions = KFileItem::Unknown;
  m_bMarked = false;
  m_bLink = false;
  m_bIsLocalURL = _url.isLocalFile();
  m_bMimeTypeKnown = false;
  m_hidden = Auto;
  m_guessedMimeType = QString::null;
  m_metaInfo = KFileMetaInfo();

  if ( d )
    d->iconName = QString::null;

  readUDSEntry( _urlIsDirectory );
  init( _determineMimeTypeOnDemand );
}
bool Katalysator2Doc::openDocument(const KURL& url, const char *format /*=0*/)
{
  QString tmpfile;
  if (url.isLocalFile())
  	tmpfile=url.path();
  else if (!KIO::NetAccess::download( url, tmpfile ))
  	{
  		KNotifyClient::event(i18n("File couldn't be downloaded!"));
  		return false;
  	}
  /////////////////////////////////////////////////
  // TODO: Add your document opening code here
	
  QFile f( tmpfile );
  if ( !f.open( IO_ReadOnly ) )
      return false;
  if ( !doc->setContent( &f ) ) {
      f.close();
      return false;
  }
  f.close();
  QDomElement docElem = doc->documentElement();
  cout << "New Document:"<<docElem.tagName() << endl;

  /////////////////////////////////////////////////

  KIO::NetAccess::removeTempFile( tmpfile );

  modified=false;
  return true;
}
void DebuggerManager::slotScriptRun()
{
  if(m_window->tabEditor()->count() == 0)
  {
    m_window->openFile();
    if(m_window->tabEditor()->count() == 0)
    {
      //couldn't open the file for some reason
      return;
    }
  }

  if(m_activeDebugger && m_activeDebugger->isRunning()) 
  {
    m_activeDebugger->stop();
  }

  KURL url = m_window->tabEditor()->currentDocumentURL();

  if(!url.isLocalFile())
  {
    m_window->showSorry("Unable to run non-local file");    
  }
  else
  {
    Session::self()->start(url, m_window->cbArguments()->currentText());
  }
}
Example #6
0
void Page::userStyleSheetLocationChanged()
{
    // FIXME: Eventually we will move to a model of just being handed the sheet
    // text instead of loading the URL ourselves.
    KURL url = m_settings->userStyleSheetLocation();
    if (url.isLocalFile())
        m_userStyleSheetPath = url.fileSystemPath();
    else
        m_userStyleSheetPath = String();

    m_didLoadUserStyleSheet = false;
    m_userStyleSheet = String();
    m_userStyleSheetModificationTime = 0;
    
    // Data URLs with base64-encoded UTF-8 style sheets are common. We can process them
    // synchronously and avoid using a loader. 
    if (url.protocolIs("data") && url.string().startsWith("data:text/css;charset=utf-8;base64,")) {
        m_didLoadUserStyleSheet = true;
        
        const unsigned prefixLength = 35;
        Vector<char> encodedData(url.string().length() - prefixLength);
        for (unsigned i = prefixLength; i < url.string().length(); ++i)
            encodedData[i - prefixLength] = static_cast<char>(url.string()[i]);

        Vector<char> styleSheetAsUTF8;
        if (base64Decode(encodedData, styleSheetAsUTF8))
            m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size());
    }
    
    for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
        if (frame->document())
            frame->document()->clearPageUserSheet();
    }
}
Example #7
0
void KMahjongg::saveGame() {

    // Get the name of the file to save
    KURL url = KFileDialog::getSaveURL( NULL, "*.kmgame", this, i18n("Save Game" ) );

    if ( url.isEmpty() )
	return;

   if( !url.isLocalFile() )
   {
      KMessageBox::sorry( this, i18n( "Only saving to local files currently supported." ) );
      return;
   }

    FILE *outFile = fopen( QFile::encodeName(url.path()), "w");
    if (outFile == NULL) {
	KMessageBox::sorry(this,
		i18n("Could not write to file. Aborting."));
	return;
    }

    // stick in the magic id string
    fprintf(outFile, "%s\n", gameMagic);

    // Now stick in the elapsed time for the game
    fprintf(outFile, "%s\n", gameTimer->toString().utf8().data());


    // chuck in all the game data
    fwrite(&bw->Game, sizeof(GAMEDATA), 1, outFile);

    // close the file before exit
    fclose(outFile);
}
Example #8
0
void EvaChatView::slotSaveImageAs()
{
    TQString name = TQString::fromLatin1("index.html");;
    if ( !d->m_suggestedFilename.isEmpty() )
        name = d->m_suggestedFilename;
    else if ( !d->m_imageURL.fileName().isEmpty() )
        name = d->m_imageURL.fileName();

    KURL destURL;
    int query;
    do {
        query = KMessageBox::Yes;
        destURL = KFileDialog::getSaveURL( TQDir::homeDirPath() + "/" + name, TQString::null, 0, i18n( "Save Image As" ) );
        if( destURL.isLocalFile() ) {
            TQFileInfo info( destURL.path() );
            if( info.exists() ) {
                // TODO: use TDEIO::RenameDlg (shows more information)
                query = KMessageBox::warningContinueCancel( 0, i18n( "A file named \"%1\" already exists. " "Are you sure you want to overwrite it?" ).arg( info.fileName() ), i18n( "Overwrite File?" ), i18n( "Overwrite" ) );
            }
        }
    } while ( query == KMessageBox::Cancel );

    if ( destURL.isValid() )
        TDEIO::file_copy(d->m_imageURL, destURL, -1, true /*overwrite*/);
}
Example #9
0
bool GMXXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
  KURL url = KFileDialog::getSaveURL( ":xxport_gmx", GMX_FILESELECTION_STRING );
  if ( url.isEmpty() )
      return true;

  if ( !url.isLocalFile() ) {
    KTempFile tmpFile;
    if ( tmpFile.status() != 0 ) {
      QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
      KMessageBox::error( parentWidget(), txt.arg( url.url() )
                          .arg( strerror( tmpFile.status() ) ) );
      return false;
    }

    doExport( tmpFile.file(), list );
    tmpFile.close();

    return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
  } else {
    QString filename = url.path();
    QFile file( filename );

    if ( !file.open( IO_WriteOnly ) ) {
      QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
      KMessageBox::error( parentWidget(), txt.arg( filename ) );
      return false;
    }

    doExport( &file, list );
    file.close();

    return true;
  }
}
Example #10
0
void TopLevel::openNetFile( const KURL &u)
{
  if ( !u.isValid() )
  {
	KMessageBox::error(this, i18n("Malformed URL"));
	return;
  }

  if ( u.isLocalFile() )
  {
    QString string = i18n("Loading '%1'").arg(u.path());
    statusbar->message(string);
    openadd( u.path());
    statusbar->clear();
  }
  else
  {
    statusbar->message(i18n("Downloading..."));
    QString tmpFile = QString::null;
    if ( KIO::NetAccess::download( u, tmpFile, this ) )
    {
      openadd( tmpFile );
      setCaption( u.prettyURL() );
    }
    statusbar->clear();
    KIO::NetAccess::removeTempFile( tmpFile );
  }
}
Example #11
0
/** expands an archiv, if possible */
bool BaseTreeView::expandArchiv (KFileTreeViewItem *item)
{
  if (!item) return false;
  KURL urlToOpen = item->url();

  if ( ! urlToOpen.isLocalFile()) return false;

  QString mimeType = KMimeType::findByURL(urlToOpen)->name();

  if ( mimeType == "application/x-tgz" ||
       mimeType == "application/x-tbz" ||
       mimeType == "application/x-tar" ) //it is an archiv
    urlToOpen.setProtocol("tar");
  else
    if ( mimeType == "application/x-zip" ) //it is an archiv
      urlToOpen.setProtocol("zip");
    else
      return false;

  // change status if there is already a sub branch
  if (item->isExpandable()) {
    item->setOpen( ! item->isOpen());
    return true;
  };

  KFileTreeBranch *kftb = new BaseTreeBranch(this, urlToOpen, item->text(0), *(item->pixmap(0)), true, item);
  addBranch(kftb);  // connecting some signals
  kftb->populate(urlToOpen, item);
  item->setExpandable(true);
  item->setOpen(true);
  return true;
}
Example #12
0
void TDMAppearanceWidget::iconLoaderDropEvent(TQDropEvent *e)
{
    KURL pixurl;
    bool istmp;

    KURL *url = decodeImgDrop(e, this);
    if (url) {

	// we gotta check if it is a non-local file and make a tmp copy at the hd.
	if(!url->isLocalFile()) {
	    pixurl.setPath(TDEGlobal::dirs()->resourceDirs("data").last() +
		     "tdm/pics/" + url->fileName());
	    TDEIO::NetAccess::copy(*url, pixurl, parentWidget());
	    istmp = true;
	} else {
	    pixurl = *url;
	    istmp = false;
	}

	// By now url should be "file:/..."
	if (!setLogo(pixurl.path())) {
	    TDEIO::NetAccess::del(pixurl, parentWidget());
	    TQString msg = i18n("There was an error loading the image:\n"
			       "%1\n"
			       "It will not be saved.")
			       .arg(pixurl.path());
	    KMessageBox::sorry(this, msg);
	}

	delete url;
    }
}
Example #13
0
bool KateApp::openURL (const KURL &url, const QString &encoding, bool isTempFile)
{
  KateMainWindow *mainWindow = activeMainWindow ();

  if (!mainWindow)
    return false;

  QTextCodec *codec = encoding.isEmpty() ? 0 : QTextCodec::codecForName(encoding.latin1());

  kdDebug () << "OPEN URL "<< encoding << endl;

  // this file is no local dir, open it, else warn
  bool noDir = !url.isLocalFile() || !QDir (url.path()).exists();

  if (noDir)
  {
    // open a normal file
    if (codec)
      mainWindow->viewManager()->openURL( url, codec->name(), true, isTempFile );
    else
      mainWindow->viewManager()->openURL( url, QString::null, true, isTempFile );
  }
  else
    KMessageBox::sorry( mainWindow,
                        i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.").arg(url.url()) );

  return true;
}
Example #14
0
bool KDEMMEngine::load( const KURL& url, bool stream )
{
    kdDebug() << "BEGIN " << k_funcinfo << endl;

    m_isStream = stream;
    kdDebug() << "  m_url: " << m_url << endl;
    kdDebug() << "  Param: stream: " << stream << endl;
    kdDebug() << "  Param: url " << url << endl;

    if ( !url.isLocalFile() ) {         // for now
       return false;
    }

    if ( m_url == url ) {
       return true;
    } else {
       stop();
   }
    m_url = url;
    // the KDEMM  SimplePlayer dows the loading in the play method

    m_state = Engine::Idle;

    kdDebug() << "END " << k_funcinfo << endl;
    return true;
}   // load
Example #15
0
void KexiBlobTableEdit::handleInsertFromFileAction(const KURL& url)
{
	if (isReadOnly())
		return;

	QString fileName( url.isLocalFile() ? url.path() : url.prettyURL() );

	//! @todo download the file if remote, then set fileName properly
	QFile f(fileName);
	if (!f.open(IO_ReadOnly)) {
		//! @todo err msg
		return;
	}
	QByteArray ba = f.readAll();
	if (f.status()!=IO_Ok) {
		//! @todo err msg
		f.close();
		return;
	}
	f.close();
//	m_valueMimeType = KImageIO::mimeType( fileName ); 
	setValueInternal( ba, true );
	signalEditRequested();
	//emit acceptRequested();
}
Example #16
0
bool WebProcessProxy::checkURLReceivedFromWebProcess(const KURL& url)
{
    // FIXME: Consider checking that the URL is valid. Currently, WebProcess sends invalid URLs in many cases, but it probably doesn't have good reasons to do that.

    // Any other non-file URL is OK.
    if (!url.isLocalFile())
        return true;

    // Any file URL is also OK if we've loaded a file URL through API before, granting universal read access.
    if (m_mayHaveUniversalFileReadSandboxExtension)
        return true;

    // If we loaded a string with a file base URL before, loading resources from that subdirectory is fine.
    // There are no ".." components, because all URLs received from WebProcess are parsed with KURL, which removes those.
    String path = url.fileSystemPath();
    for (HashSet<String>::const_iterator iter = m_localPathsWithAssumedReadAccess.begin(); iter != m_localPathsWithAssumedReadAccess.end(); ++iter) {
        if (path.startsWith(*iter))
            return true;
    }

    // Items in back/forward list have been already checked.
    // One case where we don't have sandbox extensions for file URLs in b/f list is if the list has been reinstated after a crash or a browser restart.
    for (WebBackForwardListItemMap::iterator iter = m_backForwardListItemMap.begin(), end = m_backForwardListItemMap.end(); iter != end; ++iter) {
        if (KURL(KURL(), iter->value->url()).fileSystemPath() == path)
            return true;
        if (KURL(KURL(), iter->value->originalURL()).fileSystemPath() == path)
            return true;
    }

    // A Web process that was never asked to load a file URL should not ever ask us to do anything with a file URL.
    WTFLogAlways("Received an unexpected URL from the web process: '%s'\n", url.string().utf8().data());
    return false;
}
Example #17
0
void MyEditor::slotDroppedFile(KURL url)
{
        /////////////////    decide what to do with dropped file
        TQString text;
        if (!tempFile.isEmpty()) {
                TDEIO::NetAccess::removeTempFile(tempFile);
                tempFile=TQString();
        }

        if (url.isLocalFile())
                tempFile = url.path();
        else {
                if (KMessageBox::warningContinueCancel(0,i18n("<qt><b>Remote file dropped</b>.<br>The remote file will now be copied to a temporary file to process requested operation. This temporary file will be deleted after operation.</qt>"),0,KStdGuiItem::cont(),"RemoteFileWarning")!=KMessageBox::Continue)
                        return;
                if (!TDEIO::NetAccess::download (url, tempFile,this)) {
                        KMessageBox::sorry(this,i18n("Could not download file."));
                        return;
                }
        }


                /////////////  if dropped filename ends with gpg, pgp or asc, try to decode it
                if ((tempFile.endsWith(".gpg")) || (tempFile.endsWith(".asc")) || (tempFile.endsWith(".pgp"))) {
                        slotDecodeFile(tempFile);
                }
		else slotCheckContent(tempFile);
}
Example #18
0
static CString pathSuitableForTestResult(const char* uriString)
{
    if (!uriString)
        return CString();

    KURL uri = KURL(ParsedURLString, uriString);

    if (!uri.isLocalFile())
        return uri.string().utf8();

    String pathString = uri.path();
    size_t indexBaseName = pathString.reverseFind('/');
    String baseName;
    if (indexBaseName == notFound)
        baseName = pathString;
    else
        baseName = pathString.substring(indexBaseName + 1);

    String dirName;
    if (indexBaseName != notFound) {
        size_t indexDirName = pathString.reverseFind('/', indexBaseName - 1);
        if (indexDirName != notFound)
            dirName = pathString.substring(indexDirName + 1, indexBaseName - indexDirName - 1);
    }

    String ret = dirName + "/" + baseName;
    return ret.utf8();
}
Example #19
0
void FileSelectDlg::updateSizeLabels()
{
	//calculate free disk space

	KURL sdir = KURL(m_downloadLocation -> url());
	while( sdir.isValid() && sdir.isLocalFile() && (!sdir.isEmpty())  && (! QDir(sdir.path()).exists()) ) 
	{
		sdir = sdir.upURL();
	}
	
	Uint64 bytes_free = 0;
	if (!FreeDiskSpace(sdir.path(),bytes_free))
	{
		FreeDiskSpace(tc->getDataDir(),bytes_free);
	}
	
	Uint64 bytes_to_download = 0;
	if (root)
		bytes_to_download = root->bytesToDownload();
	else
		bytes_to_download = tc->getStats().total_bytes;

	lblFree->setText(kt::BytesToString(bytes_free));
	lblRequired->setText(kt::BytesToString(bytes_to_download));

	if (bytes_to_download > bytes_free)
		lblStatus->setText("<font color=\"#ff0000\">" + kt::BytesToString(-1*(long long)(bytes_free - bytes_to_download)) + i18n(" short!"));
	else
		lblStatus->setText(kt::BytesToString(bytes_free - bytes_to_download));
}
Example #20
0
bool
HelixEngine::load( const KURL &url, bool isStream )
{
   debug() << "In load " << url.url() << endl;

   if (!m_inited)
      return false;

   if (!canDecode(url))
   {
      const QString path = url.path();
      const QString ext  = path.mid( path.findRev( '.' ) + 1 ).lower();
      emit statusText( i18n("No plugin found for the %1 format").arg(ext) );
      return false;
   }

   debug() << "xfadeLength is " << m_xfadeLength << endl;
   if( m_xfadeLength > 0 && m_state == Engine::Playing )
   {
      int nextPlayer = m_current ? 0 : 1;

      // prepare the next player
      PlayerControl::stop(nextPlayer);
      resetScope(nextPlayer);
      memset(&hscope[nextPlayer], 0, sizeof(HelixScope));
      memset(&m_pfade[nextPlayer], 0, sizeof(FadeTrack));

      if (isPlaying(m_current))
      {
         m_pfade[m_current].m_fadeactive = true;
         m_pfade[m_current].m_startfadetime = PlayerControl::where(m_current);
         setFadeout(true, m_xfadeLength, m_current);
      }
      Engine::Base::load( url, false ); // we dont crossfade streams ?? do we load the base here ??
      PlayerControl::setURL( QFile::encodeName( url.url() ), nextPlayer, !isStream );
      m_isStream = false;
   }
   else
      cleanup();

   m_isStream = isStream;
   int nextPlayer;

   nextPlayer = m_current ? 0 : 1;

   Engine::Base::load( url, isStream || url.protocol() == "http" );
   m_state = Engine::Idle;
   emit stateChanged( Engine::Idle );
   m_url = url;

   if (url.isLocalFile())
      PlayerControl::setURL( QFile::encodeName( url.url() ), nextPlayer, !m_isStream );
   else
   {
      m_isStream = true;
      PlayerControl::setURL( QFile::encodeName( url.url() ), nextPlayer, !m_isStream );
   }

   return true;
}
Example #21
0
bool kateFileSelectorIsReadable ( const KURL& url )
{
  if ( !url.isLocalFile() )
    return true; // what else can we say?

  TQDir dir (url.path());
  return dir.exists ();
}
Example #22
0
void KonqSidebarTree::addURL(KonqSidebarTreeTopLevelItem* item, const KURL & url)
{
    QString path;
    if (item)
       path = item->path();
    else
       path = m_dirtreeDir.dir.path();

    KURL destUrl;

    if (url.isLocalFile() && url.fileName().endsWith(".desktop"))
    {
       QString filename = findUniqueFilename(path, url.fileName());
       destUrl.setPath(filename);
       KIO::NetAccess::copy(url, destUrl, this);
    }
    else
    {
       QString name = url.host();
       if (name.isEmpty())
          name = url.fileName();
       QString filename = findUniqueFilename(path, name);
       destUrl.setPath(filename);

       KDesktopFile cfg(filename);
       cfg.writeEntry("Encoding", "UTF-8");
       cfg.writeEntry("Type","Link");
       cfg.writeEntry("URL", url.url());
       QString icon = "folder";
       if (!url.isLocalFile())
          icon = KMimeType::favIconForURL(url);
       if (icon.isEmpty())
          icon = KProtocolInfo::icon( url.protocol() );
       cfg.writeEntry("Icon", icon);
       cfg.writeEntry("Name", name);
       cfg.writeEntry("Open", false);
       cfg.sync();
    }

    KDirNotify_stub allDirNotify( "*", "KDirNotify*" );
    destUrl.setPath( destUrl.directory() );
    allDirNotify.FilesAdded( destUrl );

    if (item)
       item->setOpen(true);
}
Example #23
0
static CString urlSuitableForTestResult(const char* uriString)
{
    KURL uri = KURL(ParsedURLString, uriString);
    if (!uri.isLocalFile())
        return CString(uriString);

    unsigned startIndex = uri.pathAfterLastSlash();
    return uri.string().substring(startIndex).utf8();
}
bool ResourceHandle::shouldContentSniffURL(const KURL& url)
{
#if PLATFORM(MAC)
    if (shouldForceContentSniffing)
        return true;
#endif
    // We shouldn't content sniff file URLs as their MIME type should be established via their extension.
    return !url.isLocalFile();
}
Example #25
0
void KexiImageContextMenu::saveAs()
{
	QString origFilename, fileExtension;
	bool dataIsEmpty = false;
	emit aboutToSaveAsRequested(origFilename, fileExtension, dataIsEmpty);

	if (dataIsEmpty) {
		kdWarning() << "KexiImageContextMenu::saveAs(): no data!" << endl;
		return;
	}
	if (!origFilename.isEmpty())
		origFilename = QString("/") + origFilename;

	if (fileExtension.isEmpty()) {
		// PNG data is the default
		fileExtension = "png";
	}
	
#ifdef Q_WS_WIN
	QString recentDir;
	QString fileName = QFileDialog::getSaveFileName(
		KFileDialog::getStartURL(":LastVisitedImagePath", recentDir).path() + origFilename,
		convertKFileDialogFilterToQFileDialogFilter(KImageIO::pattern(KImageIO::Writing)), 
		this, 0, i18n("Save Image to File"));
#else
	//! @todo add originalFileName! (requires access to KRecentDirs)
	QString fileName = KFileDialog::getSaveFileName(
		":LastVisitedImagePath", KImageIO::pattern(KImageIO::Writing), this, i18n("Save Image to File"));
#endif
	if (fileName.isEmpty())
		return;
	
	if (QFileInfo(fileName).extension().isEmpty())
		fileName += (QString(".")+fileExtension);
	kdDebug() << fileName << endl;
	KURL url;
	url.setPath( fileName );

#ifdef Q_WS_WIN
	//save last visited path
	if (url.isLocalFile())
		KRecentDirs::add(":LastVisitedImagePath", url.directory());
#endif

	QFile f(fileName);
	if (f.exists() && KMessageBox::Yes != KMessageBox::warningYesNo(this, 
		"<qt>"+i18n("File \"%1\" already exists."
		"<p>Do you want to replace it with a new one?")
		.arg(QDir::convertSeparators(fileName))+"</qt>",0, 
		KGuiItem(i18n("&Replace")), KGuiItem(i18n("&Don't Replace"))))
	{
		return;
	}

//! @todo use KURL?
	emit saveAsRequested(fileName);
}
Example #26
0
void Project::insertFile(const KURL& nameURL, bool repaint )
{
  if (d->excludeRx.exactMatch(nameURL.path()))
      return;
  KURL url = nameURL;

  if ( !d->baseURL.isParentOf(url) )
  {
    KURLRequesterDlg *urlRequesterDlg = new KURLRequesterDlg( d->baseURL.prettyURL(), d->m_mainWindow, "");
    urlRequesterDlg->setCaption(i18n("%1: Copy to Project").arg(nameURL.prettyURL(0, KURL::StripFileProtocol)));
    urlRequesterDlg->urlRequester()->setMode( KFile::Directory | KFile::ExistingOnly);
    urlRequesterDlg->exec();
    KURL destination = urlRequesterDlg->selectedURL();
    if (destination.isLocalFile())
    {
      QDir dir(destination.path());
      destination.setPath(dir.canonicalPath());
    }
    delete urlRequesterDlg;
    if ( !destination.isEmpty() )
    {
      CopyTo *dlg = new CopyTo(d->baseURL);
      connect(dlg, SIGNAL(deleteDialog(CopyTo*)), d,
                   SLOT(slotDeleteCopytoDlg(CopyTo*)));
      url = dlg->copy( nameURL, destination );
    }
    else  // Copy canceled, addition aborted
    {
      return;
    }
  }
  QDomElement  el;
  while ( d->baseURL.isParentOf(url) )
  {
    if ( !d->m_projectFiles.contains(url) )
    {
      el = d->dom.createElement("item");
      el.setAttribute("url", QuantaCommon::qUrl( QExtFileInfo::toRelative(url, d->baseURL) ));
      d->dom.firstChild().firstChild().appendChild( el );
      KURL u = url.upURL();
      ProjectURL *parentURL = d->m_projectFiles.find(u);
      int uploadStatus = 1;
      if (parentURL)
        uploadStatus = parentURL->uploadStatus;
      d->m_projectFiles.insert( new ProjectURL(url, "", uploadStatus, false, el) );
    }
    url.setPath(url.directory(false));
  }
  emit eventHappened("after_project_add", url.url(), QString::null);
  setModified();
  if ( repaint )
  {
    emit reloadTree( &(d->m_projectFiles), false, QStringList());
    emit newStatus();
  }
}
Example #27
0
QString PerforcePart::currentFile()
{
    KParts::ReadOnlyPart *part = dynamic_cast<KParts::ReadOnlyPart*>( partController()->activePart() );
    if ( part ) {
        KURL url = part->url();
        if ( url.isLocalFile() )
            return url.path();
    }
    return QString::null;
}
Example #28
0
void MrmlPart::enableExtensionActions( const KURL& url, bool enable )
{
    bool del = KProtocolInfo::supportsDeleting( url );
    emit m_browser->enableAction( "copy", enable );
    emit m_browser->enableAction( "trash", del );
    emit m_browser->enableAction( "del",   del );
    emit m_browser->enableAction( "shred", url.isLocalFile() );
    emit m_browser->enableAction( "properties", enable );
    // emit m_browser->enableAction( "print", enable ); // ### later
}
Example #29
0
void KuickShow::dirSelected( const KURL& url )
{
    if ( url.isLocalFile() )
        setCaption( url.path() );
    else
        setCaption( url.prettyURL() );

    cmbPath->setURL( url );
    statusBar()->changeItem( url.prettyURL(), URL_ITEM );
}
Example #30
0
KABC::Picture ImageLoader::loadPicture(const KURL &url, bool *ok)
{
    KABC::Picture picture;
    QString tempFile;

    if(url.isEmpty())
        return picture;

    (*ok) = false;

    QImage image;
    if(url.isLocalFile())
    {
        image.load(url.path());
        picture.setData(image);
        (*ok) = true;
    }
    else if(KIO::NetAccess::download(url, tempFile, mParent))
    {
        image.load(tempFile);
        picture.setData(image);
        (*ok) = true;
        KIO::NetAccess::removeTempFile(tempFile);
    }

    if(!(*ok))
    {
        // image does not exist (any more)
        KMessageBox::sorry(mParent, i18n("This contact's image cannot be found."));
        return picture;
    }

    QPixmap pixmap = picture.data();

    QPixmap selectedPixmap = KPIM::KPixmapRegionSelectorDialog::getSelectedImage(pixmap, 100, 140, mParent);
    if(selectedPixmap.isNull())
    {
        (*ok) = false;
        return picture;
    }

    image = selectedPixmap;
    if(image.height() != 140 || image.width() != 100)
    {
        if(image.height() > image.width())
            image = image.scaleHeight(140);
        else
            image = image.scaleWidth(100);
    }

    picture.setData(image);
    (*ok) = true;

    return picture;
}