diff options
| author | 2008-07-16 13:59:15 +0000 | |
|---|---|---|
| committer | 2008-07-16 13:59:15 +0000 | |
| commit | 2c3ab1d1dadbe925b7375e6b1ac4501982ec2e99 (patch) | |
| tree | 058288b843c5ca1d4ae812dca853eb1aa110b86e | |
| parent | fix for #34 (please test) (diff) | |
| download | KVIrc-2c3ab1d1dadbe925b7375e6b1ac4501982ec2e99.tar.gz KVIrc-2c3ab1d1dadbe925b7375e6b1ac4501982ec2e99.tar.bz2 KVIrc-2c3ab1d1dadbe925b7375e6b1ac4501982ec2e99.zip | |
reverted #2080, /me donkey
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2081 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | src/kvilib/file/kvi_fileutils.cpp | 38 | ||||
| -rw-r--r-- | src/kvilib/file/kvi_fileutils.h | 8 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_window.cpp | 9 | ||||
| -rw-r--r-- | src/modules/reguser/dialog.cpp | 21 |
4 files changed, 63 insertions, 13 deletions
diff --git a/src/kvilib/file/kvi_fileutils.cpp b/src/kvilib/file/kvi_fileutils.cpp index e67298d27..8fec5c2c2 100644 --- a/src/kvilib/file/kvi_fileutils.cpp +++ b/src/kvilib/file/kvi_fileutils.cpp @@ -37,6 +37,7 @@ #include <QTextCodec>
#include <QTextStream>
+
namespace KviFileUtils
{
/*
@@ -435,6 +436,43 @@ namespace KviFileUtils }
};
+static char hexchars[16] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' };
+
+
+void kvi_encodeFileName(KviStr & path)
+{
+ QString szPath(path.ptr());
+ kvi_encodeFileName(szPath);
+ path=szPath;
+}
+
+void kvi_encodeFileName(QString & path)
+{
+ QString src(path);
+ path="";
+ for(int i=0;i<src.length();i++)
+ {
+ QChar cur=src[i];
+ if( ! (cur.isLetter() || cur.isDigit() || cur==' ' || cur=='_' || cur=='.' || cur=='#' || cur=='%') )
+ {
+ if(cur.row()!=0)
+ {
+ path+='%';
+ path+=hexchars[cur.row() >> 4];
+ path+=hexchars[cur.row() & 15];
+ }
+ path+='%';
+ path+=hexchars[cur.cell() >> 4];
+ path+=hexchars[cur.cell() & 15];
+ } else if (cur=='%')
+ {
+ path+="%%";
+ } else {
+ path+=cur;
+ }
+ }
+}
+
//================ kvi_isAbsolutePath ===============//
bool kvi_isAbsolutePath(const char *path)
diff --git a/src/kvilib/file/kvi_fileutils.h b/src/kvilib/file/kvi_fileutils.h index e4a08b6d9..ed5fd2333 100644 --- a/src/kvilib/file/kvi_fileutils.h +++ b/src/kvilib/file/kvi_fileutils.h @@ -44,6 +44,8 @@ // #warning "or should it be availible only for dirbrowser module ?" namespace KviFileUtils { + //extern KVILIB_API bool readLine(QFile * f,QString &szBuffer,bool bClearBuffer = true); + //extern KVILIB_API bool loadFileStripCR(const QString &szPath,QString &szBuffer); // loads the file at szPath to szBuffer eventually converting from utf8 extern KVILIB_API bool loadFile(const QString &szPath,QString &szBuffer,bool bUtf8 = true); @@ -94,8 +96,14 @@ namespace KviFileUtils }; // ALL THIS STUFF BELOW SHOULD DIE: IF YOU SEE IT, REPLACE WITH THE FUNCTIONS IN THE NAMESPACE ABOVE + // Returns true if the path begins with '/' KVILIB_API extern bool kvi_isAbsolutePath(const char *path); +// Translates ANY string into a valid filename (with no path!) +// There is NO way to come back to the original string +// the algo is one-way only +KVILIB_API extern void kvi_encodeFileName(KviStr & path); +KVILIB_API extern void kvi_encodeFileName(QString & path); // Reads a single line from the file and returns false if EOF was encountered. KVILIB_API extern bool kvi_readLine(QFile *f,KviStr &str); diff --git a/src/kvirc/ui/kvi_window.cpp b/src/kvirc/ui/kvi_window.cpp index f591e13ad..6c5d2b521 100644 --- a/src/kvirc/ui/kvi_window.cpp +++ b/src/kvirc/ui/kvi_window.cpp @@ -68,7 +68,6 @@ #include <QEvent> #include <QCloseEvent> #include <QIcon> -#include <QUrl> #ifdef COMPILE_CRYPT_SUPPORT #include "kvi_crypt.h" @@ -562,7 +561,8 @@ void KviWindow::getDefaultLogFileName(QString &buffer) date=dt.toString("yyyy.MM.dd"); QString base; getBaseLogFileName(base); - base = QUrl(base).toEncoded(); + kvi_encodeFileName(base); + base.replace("%%2e","%2e"); base=base.toLower(); QString tmp; if(KVI_OPTION_BOOL(KviOption_boolGzipLogs)) @@ -572,6 +572,11 @@ void KviWindow::getDefaultLogFileName(QString &buffer) g_pApp->getLocalKvircDirectory(buffer,KviApp::Log,tmp); } +/*void KviWindow::getBaseLogFileName(KviStr &buffer) +{ + buffer = m_szName; +}*/ + void KviWindow::getBaseLogFileName(QString &buffer) { buffer = m_szName; diff --git a/src/modules/reguser/dialog.cpp b/src/modules/reguser/dialog.cpp index 5cc9c4a2c..1b883c455 100644 --- a/src/modules/reguser/dialog.cpp +++ b/src/modules/reguser/dialog.cpp @@ -36,8 +36,8 @@ #include "kvi_options.h"
#include "kvi_file.h"
#include "kvi_filedialog.h"
-#include "kvi_fileutils.h"
#include "kvi_msgbox.h"
+#include "kvi_fileutils.h"
#include "kvi_settings.h"
#include "kvi_stringconversion.h"
#include "kvi_options.h"
@@ -59,7 +59,6 @@ #include <QEvent>
#include <QCloseEvent>
#include <QAbstractItemView>
-#include <QUrl>
#define LVI_ICON_SIZE 32
#define LVI_BORDER 4
@@ -815,23 +814,23 @@ void KviRegisteredUsersDialog::importClicked() if(img.isNull())debug("Ops.. readed a null image ?");
- QString fName = QUrl(u->name()).toEncoded();
+ KviStr fName = u->name();
+ kvi_encodeFileName(fName);
- QString fPath;
+ KviStr fPath;
int rnm = 0 ;
do
{
- g_pApp->getLocalKvircDirectory(fPath,KviApp::Avatars,fName);
- fPath+= rnm;
- fPath+= ".png";
+ g_pApp->getLocalKvircDirectory(fPath,KviApp::Avatars,fName.ptr());
+ fPath.append(KviStr::Format,"%d.png",rnm);
rnm++;
- } while(KviFileUtils::fileExists(fPath));
+ } while(KviFileUtils::fileExists(fPath.ptr()));
- if(!img.save(fPath,"PNG"))
+ if(!img.save(fPath.ptr(),"PNG"))
{
- debug("Can't save image %s",fPath.toUtf8().data());
+ debug("Can't save image %s",fPath.ptr());
} else {
- u->setProperty("avatar",fPath);
+ u->setProperty("avatar",fPath.ptr());
}
}
}
|
