pix_uploader/0000755000175000017500000000000011160152177012232 5ustar neonneonpix_uploader/pix_uploader.h0000644000175000017500000000015011160125513015064 0ustar neonneon#ifndef __PIX_UPLOADER_H_INCLUDED_ #define __PIX_UPLOADER_H_INCLUDED_ #include #endif pix_uploader/uploader.h0000644000175000017500000000126411160146755014226 0ustar neonneon#ifndef __UPLOADER_H_INCLUDED_ #define __UPLOADER_H_INCLUDED_ #include #include #include #include #include #include #include #include #include #include "uploading_window.h" class Uploader : public QObject { Q_OBJECT public: Uploader( ); private: QHttp * http; QList queue; UploadingWindow * uploading_window; QList< QByteArray > links; void Process( const QString & ); private slots: void UploadDone(); void GalleryDone(); public: void Upload( const QList< QString >& toUpload, UploadingWindow * uploading_window ); void Upload( const QString & toUpload ); }; #endif pix_uploader/uploading_window.cpp0000644000175000017500000000210411157765062016315 0ustar neonneon#include "uploading_window.h" UploadingWindow::UploadingWindow( QWidget * parent ) : QWidget( parent ) { layMain = new QGridLayout; lblCurrentFile = new QLabel( "path" ); prgGlobal = new QProgressBar; layMain->addWidget( lblCurrentFile, 0, 0 ); layMain->addWidget( prgGlobal, 1, 0 ); setLayout(layMain); setWindowTitle( "Uploading..." ); setWindowFlags( Qt::Tool ); prgGlobal->setMinimumWidth( 400 ); // center window QDesktopWidget *desktop = QApplication::desktop(); int width = frameGeometry().width(); int height = frameGeometry().height(); int screenWidth = desktop->width(); int screenHeight = desktop->height(); int x = (screenWidth - width) / 2; int y = (screenHeight - height) / 2; move( x, y ); } void UploadingWindow::SetProgressMax( int max ) { prgGlobal->setMaximum( max ); } void UploadingWindow::SetProgress( int newValue ) { prgGlobal->setValue( newValue ); } void UploadingWindow::IncProgress() { prgGlobal->setValue( prgGlobal->value() + 1 ); } void UploadingWindow::SetFile( const QString & file ) { lblCurrentFile->setText( file ); } pix_uploader/pix_uploader.pro0000644000175000017500000000067111157507636015465 0ustar neonneon###################################################################### # Automatically generated by qmake (2.01a) ?? ????? 15 19:48:20 2009 ###################################################################### TEMPLATE = app TARGET = DEPENDPATH += . INCLUDEPATH += . QT += network # Input HEADERS += main_window.h pix_uploader.h uploading_window.h uploader.h SOURCES += main_window.cpp pix_uploader.cpp uploading_window.cpp uploader.cpp pix_uploader/Makefile0000644000175000017500000002002511160107661013667 0ustar neonneon############################################################################# # Makefile for building: pix_uploader # Generated by qmake (2.01a) (Qt 4.4.3) on: ?? ????? 18 12:07:45 2009 # Project: pix_uploader.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile pix_uploader.pro ############################################################################# ####### Compiler, tools and options CC = gcc CXX = g++ DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. LINK = g++ LFLAGS = LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtNetwork -lQtCore -lpthread AR = ar cqs RANLIB = QMAKE = /usr/bin/qmake TAR = tar -cf COMPRESS = gzip -9f COPY = cp -f SED = sed COPY_FILE = $(COPY) COPY_DIR = $(COPY) -r INSTALL_FILE = install -m 644 -p INSTALL_DIR = $(COPY_DIR) INSTALL_PROGRAM = install -m 755 -p DEL_FILE = rm -f SYMLINK = ln -sf DEL_DIR = rmdir MOVE = mv -f CHK_DIR_EXISTS= test -d MKDIR = mkdir -p ####### Output directory OBJECTS_DIR = ./ ####### Files SOURCES = main_window.cpp \ pix_uploader.cpp \ uploading_window.cpp \ uploader.cpp moc_main_window.cpp \ moc_uploading_window.cpp \ moc_uploader.cpp OBJECTS = main_window.o \ pix_uploader.o \ uploading_window.o \ uploader.o \ moc_main_window.o \ moc_uploading_window.o \ moc_uploader.o DIST = /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/linux.conf \ /usr/share/qt4/mkspecs/qconfig.pri \ /usr/share/qt4/mkspecs/features/qt_functions.prf \ /usr/share/qt4/mkspecs/features/qt_config.prf \ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ /usr/share/qt4/mkspecs/features/default_pre.prf \ /usr/share/qt4/mkspecs/features/release.prf \ /usr/share/qt4/mkspecs/features/default_post.prf \ /usr/share/qt4/mkspecs/features/warn_on.prf \ /usr/share/qt4/mkspecs/features/qt.prf \ /usr/share/qt4/mkspecs/features/unix/thread.prf \ /usr/share/qt4/mkspecs/features/moc.prf \ /usr/share/qt4/mkspecs/features/resources.prf \ /usr/share/qt4/mkspecs/features/uic.prf \ /usr/share/qt4/mkspecs/features/yacc.prf \ /usr/share/qt4/mkspecs/features/lex.prf \ pix_uploader.pro QMAKE_TARGET = pix_uploader DESTDIR = TARGET = pix_uploader first: all ####### Implicit rules .SUFFIXES: .o .c .cpp .cc .cxx .C .cpp.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" .cc.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" .cxx.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" .C.o: $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" .c.o: $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" ####### Build rules all: Makefile $(TARGET) $(TARGET): $(OBJECTS) $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) Makefile: pix_uploader.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/linux.conf \ /usr/share/qt4/mkspecs/qconfig.pri \ /usr/share/qt4/mkspecs/features/qt_functions.prf \ /usr/share/qt4/mkspecs/features/qt_config.prf \ /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ /usr/share/qt4/mkspecs/features/default_pre.prf \ /usr/share/qt4/mkspecs/features/release.prf \ /usr/share/qt4/mkspecs/features/default_post.prf \ /usr/share/qt4/mkspecs/features/warn_on.prf \ /usr/share/qt4/mkspecs/features/qt.prf \ /usr/share/qt4/mkspecs/features/unix/thread.prf \ /usr/share/qt4/mkspecs/features/moc.prf \ /usr/share/qt4/mkspecs/features/resources.prf \ /usr/share/qt4/mkspecs/features/uic.prf \ /usr/share/qt4/mkspecs/features/yacc.prf \ /usr/share/qt4/mkspecs/features/lex.prf \ /usr/lib/libQtGui.prl \ /usr/lib/libQtNetwork.prl \ /usr/lib/libQtCore.prl $(QMAKE) -unix -o Makefile pix_uploader.pro /usr/share/qt4/mkspecs/common/g++.conf: /usr/share/qt4/mkspecs/common/unix.conf: /usr/share/qt4/mkspecs/common/linux.conf: /usr/share/qt4/mkspecs/qconfig.pri: /usr/share/qt4/mkspecs/features/qt_functions.prf: /usr/share/qt4/mkspecs/features/qt_config.prf: /usr/share/qt4/mkspecs/features/exclusive_builds.prf: /usr/share/qt4/mkspecs/features/default_pre.prf: /usr/share/qt4/mkspecs/features/release.prf: /usr/share/qt4/mkspecs/features/default_post.prf: /usr/share/qt4/mkspecs/features/warn_on.prf: /usr/share/qt4/mkspecs/features/qt.prf: /usr/share/qt4/mkspecs/features/unix/thread.prf: /usr/share/qt4/mkspecs/features/moc.prf: /usr/share/qt4/mkspecs/features/resources.prf: /usr/share/qt4/mkspecs/features/uic.prf: /usr/share/qt4/mkspecs/features/yacc.prf: /usr/share/qt4/mkspecs/features/lex.prf: /usr/lib/libQtGui.prl: /usr/lib/libQtNetwork.prl: /usr/lib/libQtCore.prl: qmake: FORCE @$(QMAKE) -unix -o Makefile pix_uploader.pro dist: @$(CHK_DIR_EXISTS) .tmp/pix_uploader1.0.0 || $(MKDIR) .tmp/pix_uploader1.0.0 $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/pix_uploader1.0.0/ && $(COPY_FILE) --parents main_window.h pix_uploader.h uploading_window.h uploader.h .tmp/pix_uploader1.0.0/ && $(COPY_FILE) --parents main_window.cpp pix_uploader.cpp uploading_window.cpp uploader.cpp .tmp/pix_uploader1.0.0/ && (cd `dirname .tmp/pix_uploader1.0.0` && $(TAR) pix_uploader1.0.0.tar pix_uploader1.0.0 && $(COMPRESS) pix_uploader1.0.0.tar) && $(MOVE) `dirname .tmp/pix_uploader1.0.0`/pix_uploader1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/pix_uploader1.0.0 clean:compiler_clean -$(DEL_FILE) $(OBJECTS) -$(DEL_FILE) *~ core *.core ####### Sub-libraries distclean: clean -$(DEL_FILE) $(TARGET) -$(DEL_FILE) Makefile mocclean: compiler_moc_header_clean compiler_moc_source_clean mocables: compiler_moc_header_make_all compiler_moc_source_make_all compiler_moc_header_make_all: moc_main_window.cpp moc_uploading_window.cpp moc_uploader.cpp compiler_moc_header_clean: -$(DEL_FILE) moc_main_window.cpp moc_uploading_window.cpp moc_uploader.cpp moc_main_window.cpp: main_window.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) main_window.h -o moc_main_window.cpp moc_uploading_window.cpp: uploading_window.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) uploading_window.h -o moc_uploading_window.cpp moc_uploader.cpp: uploading_window.h \ uploader.h /usr/bin/moc-qt4 $(DEFINES) $(INCPATH) uploader.h -o moc_uploader.cpp compiler_rcc_make_all: compiler_rcc_clean: compiler_image_collection_make_all: qmake_image_collection.cpp compiler_image_collection_clean: -$(DEL_FILE) qmake_image_collection.cpp compiler_moc_source_make_all: compiler_moc_source_clean: compiler_uic_make_all: compiler_uic_clean: compiler_yacc_decl_make_all: compiler_yacc_decl_clean: compiler_yacc_impl_make_all: compiler_yacc_impl_clean: compiler_lex_make_all: compiler_lex_clean: compiler_clean: compiler_moc_header_clean ####### Compile main_window.o: main_window.cpp main_window.h \ uploading_window.h \ uploader.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main_window.o main_window.cpp pix_uploader.o: pix_uploader.cpp pix_uploader.h \ main_window.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o pix_uploader.o pix_uploader.cpp uploading_window.o: uploading_window.cpp uploading_window.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o uploading_window.o uploading_window.cpp uploader.o: uploader.cpp uploader.h \ uploading_window.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o uploader.o uploader.cpp moc_main_window.o: moc_main_window.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_main_window.o moc_main_window.cpp moc_uploading_window.o: moc_uploading_window.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_uploading_window.o moc_uploading_window.cpp moc_uploader.o: moc_uploader.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_uploader.o moc_uploader.cpp ####### Install install: FORCE uninstall: FORCE FORCE: pix_uploader/uploader.cpp0000644000175000017500000001025111160150027014540 0ustar neonneon#include "uploader.h" #include using namespace std; Uploader::Uploader( ) : QObject () {} void Uploader::Upload( const QList< QString >& toUpload, UploadingWindow * wnd ) { if ( !uploading_window ) return; queue = toUpload; uploading_window = wnd; uploading_window->SetProgressMax( queue.count() ); uploading_window->SetProgress( 0 ); if ( queue.count() ) Process( queue.takeFirst() ); /* for ( QList< QString >::const_iterator i = toUpload.constBegin(); i != toUpload.constEnd(); ++i ) { uploading_window->SetFile( *i ); Upload( *i ); uploading_window->IncProgress(); }*/ } void Uploader::Process( const QString & file ) { uploading_window->SetFile( file ); Upload( file ); } void Uploader::Upload( const QString & path ) { QUrl url( "http://pix.academ.org/" ); QHttpRequestHeader header( "POST", url.path() ); // TODO: remove constant value from boundary. // use something like md5 or gettimeofday or getuid to generate unique boundary QString boundary( "---------------------------9163698821807300243581667708" ); QString boundaryPart( "--" + boundary ); QString boundaryEnd( "--" + boundary + "--" ); // global headers header.setValue("Host", url.host()); header.setValue("User-Agent", "pix uploader"); header.setValue("Content-Type", "multipart/form-data; boundary=" + boundary); // determine MIME type // TODO: try to find some QT class which can do the same thing QString mimeType("image/");; if ( path.endsWith( "png", Qt::CaseInsensitive ) ) { mimeType.append( "png" ); } else if ( path.endsWith( "jpg", Qt::CaseInsensitive ) || path.endsWith( "jpeg", Qt::CaseInsensitive ) ) { mimeType.append( "jpeg" ); } else if ( path.endsWith( "gif", Qt::CaseInsensitive) ) { mimeType.append( "gif" ); } // extract file name QFileInfo fi( path ); QString fileName = fi.fileName(); // build multipart request QByteArray data; data.append( boundaryPart + "\r\n" ); data.append( "Content-Disposition: form-data; name=\"action\"\r\n\r\nupload_image\r\n" ); data.append( boundaryPart + "\r\n" ); data.append( "Content-Disposition: form-data; name=\"image\"; filename=\"" + fileName + "\"\r\n" ); data.append( "Content-Type: " + mimeType + "\r\n\r\n"); // add file data QFile file( path ); file.open( QIODevice::ReadOnly ); data.append( file.readAll() ); file.close(); // finalize form data.append( "\r\n" + boundaryEnd + "\r\n" ); // add content length header.setContentLength( data.length() ); // do the request, handle signals http = new QHttp( url.host(), 80 ); connect( http, SIGNAL( done( bool ) ), this, SLOT( UploadDone() ) ); http->request( header, data ); } void Uploader::UploadDone() { QByteArray data = http->readAll(); QByteArray beginningTag = ""; int start = data.indexOf( beginningTag, 0 ); int end = data.indexOf( endingTag, start + beginningTag.length() + 1 ); if ( start && end ) { QByteArray link = data.mid( start + beginningTag.length(), end - start - beginningTag.length() ); link = link.mid( 26 ); // cut "http://pix.academ.org/" links.push_back( link ); } uploading_window->IncProgress(); if ( queue.count() ) Process( queue.takeFirst() ); else { // create gallery link QUrl url( "http://pix.academ.org/gallery.php" ); QHttpRequestHeader header( "POST", url.path() ); header.setValue("Host", url.host()); header.setValue("Content-Type", "application/x-www-form-urlencoded" ); QByteArray data; for ( QList::const_iterator i = links.constBegin(); i != links.constEnd(); ++i ) { data.append( "img[]=" + *i + "&" ); } header.setContentLength( data.length() ); http = new QHttp( url.host(), 80 ); connect( http, SIGNAL( done( bool ) ), this, SLOT( GalleryDone() ) ); http->request( header, data ); // QUrl url("http://google.com"); // QDesktopServices::openUrl(url); // delete uploading_window; // delete this; } } void Uploader::GalleryDone() { QByteArray data = http->readAll(); if ( data.startsWith( "ok: " ) ) { data = data.mid( 4 ); QUrl url( "http://pix.academ.org/gallery.php?id=" + data ); QDesktopServices::openUrl(url); } else { QMessageBox::critical( 0, tr("Error"), tr("Can not create gallery") ); } } pix_uploader/pix_uploader.cpp0000644000175000017500000000027111160145675015436 0ustar neonneon#include #include int main( int argc, char ** argv ) { QApplication app( argc, argv ); MainWindow window; window.show(); app.exec(); return 0; } pix_uploader/main_window.h0000644000175000017500000000205211157374741014726 0ustar neonneon#ifndef __MAIN_WINDOW_H_INCLUDED_ #define __MAIN_WINDOW_H_INCLUDED_ #include // qApp instance // Interface elements #include #include #include #include #include // misc #include class MainWindow : public QWidget { Q_OBJECT public: MainWindow( QWidget * parent = 0 ); private slots: void BrowseFiles(); void BrowseDirectory(); void RemoveFiles(); void UploadFiles(); private: //// Interface elements QGridLayout * layMain; // main window layout QVBoxLayout * layButtons; // control buttons layout QListWidget * lstFiles; // list with all selected files QPushButton * btnBrowseFiles; // browse files button QPushButton * btnBrowseDirectory; // browse directory button QPushButton * btnRemoveFiles; // remove file button QPushButton * btnRemoveAll; // remove all button QPushButton * btnUpload; // upload files button //// Other stuff void AddFile( QString const & path ); void AddDir( QString const & path, int recursive = 1 ); }; #endif pix_uploader/main_window.cpp0000644000175000017500000000711711160131414015246 0ustar neonneon#include #include #include #include MainWindow::MainWindow( QWidget * parent ) : QWidget( parent ) { setFixedSize( 600, 350 ); // Create interface elements layMain = new QGridLayout; layButtons = new QVBoxLayout; btnBrowseFiles = new QPushButton( tr("Add &File") ); btnBrowseDirectory = new QPushButton( tr("Add &Directory") ); btnRemoveFiles = new QPushButton( tr("Remove F&iles") ); btnRemoveAll = new QPushButton( tr("Remove A&ll") ); btnUpload = new QPushButton( tr("&Upload") ); lstFiles = new QListWidget; lstFiles->setSelectionMode( QAbstractItemView::ExtendedSelection ); layButtons->addWidget( btnBrowseFiles ); layButtons->addWidget( btnBrowseDirectory ); layButtons->addWidget( btnRemoveFiles ); layButtons->addWidget( btnRemoveAll ); layButtons->addWidget( btnUpload ); layButtons->addStretch( ); layMain->addWidget( lstFiles ); layMain->addLayout( layButtons, 0, 1 ); layMain->setColumnStretch( 0, 1 ); // Event handlers connect( btnBrowseFiles, SIGNAL( clicked() ), this, SLOT( BrowseFiles() ) ); connect( btnBrowseDirectory, SIGNAL( clicked() ), this, SLOT( BrowseDirectory() ) ); connect( btnRemoveFiles, SIGNAL( clicked() ), this, SLOT( RemoveFiles() ) ); connect( btnRemoveAll, SIGNAL( clicked() ), lstFiles, SLOT( clear() ) ); connect( btnUpload, SIGNAL( clicked() ), this, SLOT( UploadFiles() ) ); setLayout( layMain ); setWindowTitle( tr("PiX uploader") ); // center window QDesktopWidget *desktop = QApplication::desktop(); int width = frameGeometry().width(); int height = frameGeometry().height(); int screenWidth = desktop->width(); int screenHeight = desktop->height(); int x = (screenWidth - width) / 2; int y = (screenHeight - height) / 2; move( x, y ); } void MainWindow::BrowseFiles() { QStringList SelectedFiles = QFileDialog::getOpenFileNames( this, tr("Select files"), QDir::currentPath(), tr("Image files") + " (*.png *.gif *.jpg *.jpeg)" ); for ( QStringList::const_iterator i = SelectedFiles.constBegin(); i != SelectedFiles.constEnd(); ++i ) { AddFile( *i ); } } void MainWindow::BrowseDirectory() { QFileDialog dialog; QString SelectedDirectory = QFileDialog::getExistingDirectory( this, tr("Select directory"), QDir::currentPath() ); if ( SelectedDirectory.length() ) AddDir( SelectedDirectory ); } void MainWindow::AddFile( QString const & path ) { QList< QListWidgetItem * > existing = lstFiles->findItems( path, Qt::MatchExactly ); if ( existing.count() ) return; lstFiles->addItem( path ); } void MainWindow::AddDir( QString const & path, int recursive ) { QDir dir( path ); QRegExp rxFile( "(?:png|jpe?g|gif)$" ); // any png, jpg, jpeg ot gif file QRegExp rxBadDir( "^\\.\\.?$" ); // . and .. directories if ( !dir.exists() ) return; QFileInfoList lst = dir.entryInfoList(); for ( int i = 0; i < lst.size(); ++i ) { QFileInfo info = lst.at(i); if ( recursive && info.isDir() && !rxBadDir.exactMatch( info.fileName() ) ) { AddDir( info.absoluteFilePath(), recursive ); } else if ( info.isFile() && rxFile.indexIn( info.fileName() ) != -1 ) { AddFile( info.absoluteFilePath() ); } } } void MainWindow::RemoveFiles() { qDeleteAll( lstFiles->selectedItems() ); } void MainWindow::UploadFiles() { QList< QString > toUpload; for ( int i = 0; i < lstFiles->count(); i++ ) { toUpload.push_back( lstFiles->item(i)->text() ); } UploadingWindow * uploading_window = new UploadingWindow(); Uploader * uploader = new Uploader(); uploading_window->show(); uploading_window->activateWindow(); uploader->Upload( toUpload, uploading_window ); } pix_uploader/uploading_window.h0000644000175000017500000000115311157765025015764 0ustar neonneon#ifndef __UPLOADING_WINDOW_H_INCLUDED_ #define __UPLOADING_WINDOW_H_INCLUDED_ #include #include #include #include #include #include class UploadingWindow : public QWidget { Q_OBJECT public: UploadingWindow( QWidget * parent = 0 ); public slots: void SetProgressMax( int ); void SetProgress( int ); void IncProgress(); void SetFile( const QString & ); private slots: private: QGridLayout * layMain; // main layout QLabel * lblCurrentFile; // label with current file QProgressBar * prgGlobal; // global progressar }; #endif