misc.cpp
changeset 199 202572375c98
parent 166 325958acb69b
child 366 e95081c21da2
     1.1 --- a/misc.cpp	Mon Oct 10 11:20:25 2005 +0000
     1.2 +++ b/misc.cpp	Wed Jan 25 12:34:55 2006 +0000
     1.3 @@ -70,127 +70,6 @@
     1.4  	return QPoint ((int) (x),(int) (y));
     1.5  }
     1.6  
     1.7 -QString maskPath(QString p)
     1.8 -{
     1.9 -	// Change " " to "\ " to enable blanks in filenames
    1.10 -	p=p.replace(QChar('&'),"\\&");
    1.11 -	return p.replace(QChar(' '),"\\ ");
    1.12 -}
    1.13 -
    1.14 -QString convertToRel (const QString &src, const QString &dst)
    1.15 -{
    1.16 -	QString s=src;
    1.17 -	QString d=dst;
    1.18 -	int i;
    1.19 -
    1.20 -	if (s==d) 
    1.21 -	{
    1.22 -		// Special case, we just need the name of the file,
    1.23 -		// not the complete path
    1.24 -		i=d.findRev ("/");
    1.25 -		d=d.right (d.length()-i-1);
    1.26 -	} else
    1.27 -	{
    1.28 -		// Find relative path from src to dst
    1.29 -
    1.30 -		// Remove the first "/"
    1.31 -		if (s.section ("/",0,0).isEmpty()) 
    1.32 -		{
    1.33 -			s=s.right (s.length()-1);
    1.34 -			d=d.right (d.length()-1);
    1.35 -		}
    1.36 -		
    1.37 -		// remove identical left parts
    1.38 -		while (s.section("/",0,0) == d.section("/",0,0) ) 
    1.39 -		{
    1.40 -			i=s.find ("/");
    1.41 -			s=s.right (s.length()-i-1);
    1.42 -			d=d.right (d.length()-i-1);
    1.43 -		}
    1.44 -
    1.45 -		int srcsep=s.contains("/");
    1.46 -		int dstsep=d.contains("/");
    1.47 -		if (srcsep >=  dstsep )
    1.48 -		{
    1.49 -			// find path to go up first and then back to dst
    1.50 -			i=1;
    1.51 -			while (i<=srcsep) 
    1.52 -			{
    1.53 -				d="../"+d;
    1.54 -				i++;
    1.55 -			}	
    1.56 -		}
    1.57 -	}	
    1.58 -	return d;
    1.59 -}
    1.60 -
    1.61 -QString makeUniqueDir (QString s)
    1.62 -{
    1.63 -	char *p;
    1.64 -	int bytes=s.length();
    1.65 -	p=(char*) malloc (bytes+1);
    1.66 -	int i;
    1.67 -	for (i=0;i<bytes;i++)
    1.68 -		p[i]=s.at(i).latin1();
    1.69 -	p[bytes]=0;	
    1.70 -	QString r=mkdtemp (p);
    1.71 -	free (p);
    1.72 -	return r;
    1.73 -}
    1.74 -
    1.75 -void removeDir(QDir d)
    1.76 -{
    1.77 -	if (d.path().left(4)!="/tmp")
    1.78 -	{
    1.79 -		// FIXME testing
    1.80 -		qWarning ("misc.cpp::removeDir should remove "+d.path()+" - aborted.");
    1.81 -		return;
    1.82 -	}
    1.83 -
    1.84 -	// Traverse directories
    1.85 -	d.setFilter( QDir::Dirs| QDir::Hidden | QDir::NoSymLinks );
    1.86 -	const QFileInfoList *dirlist = d.entryInfoList();
    1.87 -	QFileInfoListIterator itdir( *dirlist );
    1.88 -	QFileInfo *fi;
    1.89 -
    1.90 -	while ( (fi = itdir.current()) != 0 ) 
    1.91 -	{
    1.92 -		if (fi->fileName() != "." && fi->fileName() != ".." )
    1.93 -		{
    1.94 -			if ( !d.cd(fi->fileName()) ) 
    1.95 -				qWarning ("removeDir() cannot find the directory "+fi->fileName());
    1.96 -			else 
    1.97 -			{
    1.98 -				// Recursively remove subdirs
    1.99 -				removeDir (d);
   1.100 -				d.cdUp();
   1.101 -			}
   1.102 -		}	
   1.103 -		++itdir;
   1.104 -	}		
   1.105 -	// Traverse files
   1.106 -	d.setFilter( QDir::Files| QDir::Hidden | QDir::NoSymLinks );
   1.107 -	const QFileInfoList *filelist = d.entryInfoList();
   1.108 -	QFileInfoListIterator itfile( *filelist );
   1.109 -
   1.110 -	while ( (fi = itfile.current()) != 0 ) 
   1.111 -	{
   1.112 -		QFile (fi->filePath()).remove();
   1.113 -		
   1.114 -		++itfile;
   1.115 -	}	
   1.116 -
   1.117 -	if (!d.rmdir(d.path()))
   1.118 -		qWarning ("removeDir("+d.path()+") failed!");
   1.119 -}		
   1.120 -
   1.121 -void makeSubDirs (const QString &s)
   1.122 -{
   1.123 -	QDir d(s);
   1.124 -	d.mkdir(s);
   1.125 -	d.mkdir ("images");	
   1.126 -	d.mkdir ("flags");	
   1.127 -}
   1.128  
   1.129  // returns masked "<" ">" "&"
   1.130  QString quotemeta(const QString &s)
   1.131 @@ -286,36 +165,3 @@
   1.132      return s;
   1.133  }	
   1.134  
   1.135 -
   1.136 -
   1.137 -ImagePreview::ImagePreview (QWidget *parent=0): QLabel (parent)
   1.138 -{
   1.139 -}
   1.140 -
   1.141 -void ImagePreview::previewUrl( const QUrl &u )
   1.142 -{
   1.143 -    QString path = u.path();
   1.144 -    QPixmap pix( path );
   1.145 -    if ( pix.isNull() )
   1.146 -        setText( QObject::tr("This is not an image.") );
   1.147 -    else
   1.148 -	{
   1.149 -		float max_w=300;
   1.150 -		float max_h=300;
   1.151 -		float r;
   1.152 -		if (pix.width()>max_w)
   1.153 -		{
   1.154 -			r=max_w / pix.width();
   1.155 -			pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
   1.156 -			// TODO not a resize, but a shrink/enlarge is needed here...
   1.157 -		}
   1.158 -		if (pix.height()>max_h)
   1.159 -		{
   1.160 -			r=max_h / pix.height();
   1.161 -			pix.resize(qRound(pix.width()*r), qRound(pix.height()*r));
   1.162 -			// TODO not a resize, but a shrink/enlarge is needed here...
   1.163 -		}
   1.164 -        setPixmap( pix );
   1.165 -	}	
   1.166 -}
   1.167 -