📄 droptestdialogbase.cpp
字号:
/****************************************************************************** Form implementation generated from reading ui file '.\droptestdialogbase.ui'**** Created: Thu May 15 11:27:45 2008** by: The User Interface Compiler (uic)**** WARNING! All changes made in this file will be lost!****************************************************************************/#include "droptestdialogbase.h"#include <qlayout.h>#include <qvariant.h>#include <qtooltip.h>#include <qwhatsthis.h>
#include <qurl.h>
#include <qtextcodec.h>
#include <qfiledialog.h>
#include <qdatastream.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qdatetime.h>
#include <qtextstream.h>
#include <qtextcodec.h>
dropLabel::dropLabel( QWidget *parent, const char *name )
:QLabel( parent, name )
{
setAcceptDrops(TRUE);
}
void dropLabel::dragEnterEvent( QDragEnterEvent *e )
{
int debug = 0;
if ( QUrlDrag::canDecode( e ) )
{
e->accept();
}
// Give the user some feedback...
QString t;
for( int i=0; e->format( i ); i++ ) {
if ( *(e->format( i )) ) {
if ( !t.isEmpty() )
t += "\n";
t += e->format( i );
}
}
// emit message( t );
setBackgroundColor(white);
}
void dropLabel::dragMoveEvent( QDragMoveEvent *e )
{
int debug = 0;
}
void dropLabel::dragLeaveEvent( QDragLeaveEvent *e )
{
int debug = 0;
}
void dropLabel::dropEvent( QDropEvent *e )
{
qWarning("dropEvent------->");
int debug = 0;
setBackgroundColor(lightGray);
// Try to decode to the data you understand...
QString str;
if ( QTextDrag::decode( e, str ) ) {
QUrl::decode( str );
str = str.right( str.length() - 8 );
str.replace( 1, 1, ":" );
str.stripWhiteSpace();
QTextCodec *codec = QTextCodec::codecForName( "UTF-8" );
QString tmp = codec->toUnicode( str );
tmp.remove( tmp.length() - 2, 2 );
setText( tmp );
emit message( tmp );
setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
return;
}
QStrList strings;
if ( QUrlDrag::decode( e, strings ) ) {
QString m("Full URLs:\n");
for (const char* u=strings.first(); u; u=strings.next())
m = m + " " + u + '\n';
QStringList files;
if ( QUrlDrag::decodeLocalFiles( e, files ) ) {
m += "Files:\n";
for (QStringList::Iterator i=files.begin(); i!=files.end(); ++i)
m = m + " " +*i + '\n';
}
// QFile file( m );
// if( file.open( IO_ReadWrite ) )
// setText( m );
emit message( m );
setMinimumSize( minimumSize().expandedTo( sizeHint() ) );
return;
}
}
/* * Constructs a droptestDialogBase which is a child of 'parent', with the * name 'name' and widget flags set to 'f' * * The dialog will by default be modeless, unless you set 'modal' to * TRUE to construct a modal dialog. */droptestDialogBase::droptestDialogBase( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ){ if ( !name ) setName( "droptestDialogBase" ); resize( 315, 510 );
QTextCodec *codec = QTextCodec::codecForName( "GBK" );
QString tname = "文档管理";
QString textname = codec->toUnicode( tname );
setCaption( textname ); setSizeGripEnabled( TRUE );
rootEdit = new QLineEdit( this );
rootEdit->setGeometry( 5, 5, 300, 30 );
QFile configFile( "settings.conf" );
if( !configFile.open( IO_ReadWrite ) )
{
return;
}
QTextStream in( &configFile );
QString str;
str = in.readLine();
rootEdit->setText( str );
addPathEdit = new QLineEdit( this );
addPathEdit->setGeometry( 5, 40, 200, 30 );
addButton = new QPushButton( this );
connect( addButton, SIGNAL(clicked()), this, SLOT(slotAddPath()) );
tname = "增加子目录";
textname = codec->toUnicode( tname );
addButton->setText( textname );
addButton->setGeometry( 215, 40, 94, 30 );
QLabel *dLabel = new QLabel( this );
dLabel->setGeometry( 5, 75, 80, 30 );
tname = "选择子目录";
textname = codec->toUnicode( tname );
dLabel->setText( textname );
subPathBox = new QComboBox( this );
subPathBox->setGeometry( 90, 75, 220, 30 );
droplabel = new dropLabel( this );
connect( droplabel, SIGNAL( message(QString &) ), this, SLOT( displayMessage(QString &) ) );
droplabel->setText("drop it!");
droplabel->setGeometry( 5, 110, 300, 320 );
fnLabel = new QLabel( this );
// fnLabel->setText( "asdfasdf" );
fnLabel->setAlignment( AlignLeft );
fnLabel->setGeometry( 5, 435, 300, 30 );
pb = new QProgressBar( this );
// pb->setTotalSteps( 100 );
pb->setGeometry( 5, 470, 300, 30 );
initSubPath( str );
connect( rootEdit, SIGNAL(textChanged ( const QString & )), this, SLOT(textChanged(QString &)) );
connect( subPathBox, SIGNAL( activated (int) ), this, SLOT(refreshLine(int)) );
}/* * Destroys the object and frees any allocated resources */droptestDialogBase::~droptestDialogBase(){ // no need to delete child widgets, Qt does it all for us
QFile configFile( "settings.conf" );
if( !configFile.open( IO_ReadWrite | IO_Truncate ) )
{
return;
}
QTextStream in( &configFile );
in << rootEdit->text();
}
void droptestDialogBase::refreshLine( int index )
{
addPathEdit->setText( subPathBox->text( index ) );
}
void droptestDialogBase::textChanged( QString &str )
{
droplabel->setText( str );
QDir rootDir( str );
subPathBox->clear();
if( rootDir.exists() )
initSubPath( str );
else
{
// droplabel->setText( str );
// rootDir.mkdir( str );
}
}
void droptestDialogBase::initSubPath( const QString &parentPath )
{
QDir rootDir( parentPath );
rootDir.setFilter( QDir::Dirs );
const QFileInfoList *dirList = rootDir.entryInfoList();
QFileInfoListIterator it( *dirList );
QFileInfo *fi;
while( fi = it.current() )
{
if( (fi->fileName() != ".") && (fi->fileName() != "..") )
subPathBox->insertItem( fi->fileName(), 0 );
++it;
}
}
void droptestDialogBase::slotAddPath()
{
if( 0 != addPathEdit->text().length() )
subPathBox->insertItem( addPathEdit->text(), 0 );
subPathBox->setCurrentItem( 0 );
QDir tmpDir( rootEdit->text() + "\\" + addPathEdit->text() );
if( !tmpDir.exists() )
tmpDir.mkdir( rootEdit->text() + "\\" + addPathEdit->text() );
}
void droptestDialogBase::displayMessage( QString &str)
{
// droplabel->setText( str );
// QTextCodec *codec = QTextCodec::codecForName( "UTF-8" );
// QString tmp = codec->toUnicode( str );
// tmp.remove( tmp.length() - 2, 2 );
QFile sfile( str );
QFileInfo finfo( sfile );
QDir dir;
if( !dir.cd( rootEdit->text() + subPathBox->currentText() ) )
{
dir.cd( rootEdit->text() );
dir.mkdir( subPathBox->currentText() );
dir.cd( subPathBox->currentText() );
}
QDate date = QDate::currentDate();
int month = date.month();
QString strmon;
if( month < 10 )
strmon = "0" + QString::number(month);
else
strmon = QString::number( month );
int day = date.day();
QString strday;
if( day < 10 )
strday = "0" + QString::number(day);
else
strday = QString::number(day);
QString tmpDate = QString::number( date.year() ) +
strmon + strday;
if( !dir.cd( tmpDate ) )
{
dir.mkdir( tmpDate );
dir.cd( tmpDate );
}
//开始拷贝
if( !finfo.isDir() )
{
QFile dfile( dir.absPath() + "\\" + finfo.fileName() );
if( !dfile.open( IO_WriteOnly ) )
{
fnLabel->setText( "dfile open failed!!!\n" );
return;
}
if( !sfile.open( IO_ReadWrite ) )
{
fnLabel->setText( "sfile open failed!!!\n" );
}
int buffsize = 256;
int len = 0;
char buf[256];
while( 1 )
{
len = sfile.readBlock( buf, 256 );
dfile.writeBlock( buf, len );
if( len != 256 )
break;
}
}
else
{
QString gDirName = dir.absPath() + "\\" + finfo.fileName();
// droplabel->setText( QString::number(gDirName.length()) );
treatDir( gDirName, str );
}
}
void droptestDialogBase::treatDir( QString &dirName, QString &sfilepath )
{
QDir testDir( dirName );
const char *a = dirName.data();
const char *b = sfilepath.data();
//droplabel->setText( sfilepath );
addPathEdit->setText( sfilepath );
if( !testDir.exists( dirName ) )
{
testDir.mkdir( dirName );
}
if( !testDir.cd( dirName ) )
return;
QDir sDir( sfilepath );
// QFile sfile( sfilepath );
const QFileInfoList *fileList = sDir.entryInfoList();
QFileInfoListIterator it( *fileList );
QFileInfo *fi;
while ( (fi=it.current()) )
{
if ( (fi->fileName() == ".") || (fi->fileName() == "..") )
{
++it;
continue;
}
if( fi->isDir() )
{
treatDir( testDir.absPath() + "\\" + fi->fileName(), sfilepath + "\\" + fi->fileName() );
}
else
{
QFile dfile( testDir.absPath() + "\\" + fi->fileName() );
if( !dfile.open( IO_WriteOnly ) )
{
fnLabel->setText( "dfile open failed!!!\n" );
return;
}
QFile sfile( sfilepath + "\\" + fi->fileName() );
if( !sfile.open( IO_ReadWrite ) )
{
fnLabel->setText( "sfile open failed!!!\n" );
}
int buffsize = 256;
int len = 0;
char buf[256];
fnLabel->setText( sfilepath + "\\" + fi->fileName() );
int totalSize = sfile.size();
pb->setTotalSteps( (totalSize / 256) + 1 );
int steps = 1;
while( 1 )
{
len = sfile.readBlock( buf, 256 );
pb->setProgress( steps++ );
dfile.writeBlock( buf, len );
if( len != 256 )
break;
}
}
++it;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -