Skip to content

Commit

Permalink
Commit source code for R6 rlease in trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
em.colombo committed Jun 28, 2013
1 parent dcdc95e commit 41e68f2
Show file tree
Hide file tree
Showing 33 changed files with 892 additions and 152 deletions.
9 changes: 8 additions & 1 deletion buddylistitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ void BuddyListItemModel::addBuddy(QString ip, qint16 port, QString username, QSt
// Add elemento to the list
if (add) {
appendRow(it);
if (ip != "") mItemsMap.insert(ip, it);
if (ip != "")
mItemsMap.insert(ip, it);
else
mMeItem = it;
}
}

Expand Down Expand Up @@ -177,3 +180,7 @@ QString BuddyListItemModel::fistBuddyIp()
return this->index(2, 0).data(BuddyListItemModel::Ip).toString();
}

void BuddyListItemModel::updateMeElement()
{
mMeItem->setData(Platform::getSystemUsername(), BuddyListItemModel::Username);
}
2 changes: 2 additions & 0 deletions buddylistitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BuddyListItemModel : public QStandardItemModel
void addBuddy(Peer& peer);
void removeBuddy(QString ip);
void showSingleBack(int idx);
void updateMeElement();
QString buddyNameByIp(QString ip);
QStandardItem* buddyByIp(QString ip);
QString fistBuddyIp();
Expand All @@ -52,6 +53,7 @@ class BuddyListItemModel : public QStandardItemModel

private:
QHash<QString, QStandardItem*> mItemsMap;
QStandardItem* mMeItem;
};

#endif // BUDDYLISTITEMMODEL_H
Binary file added dukto.icns
Binary file not shown.
13 changes: 8 additions & 5 deletions dukto.pro
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Add more folders to ship with the application, here
qml_folder.source = qml/dukto
qml_folder.target = qml
DEPLOYMENTFOLDERS = qml_folder
#qml_folder.source = qml/dukto
#qml_folder.target = qml
#DEPLOYMENTFOLDERS = qml_folder

# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =

QT += network

win32:RC_FILE = dukto.rc
win32:LIBS += libWs2_32 libole32
win32:VERSION = 5.0.0
win32:LIBS += libWs2_32 libole32 libNetapi32

mac:ICON = dukto.icns

VERSION = 6.0.0

# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
Expand Down
16 changes: 8 additions & 8 deletions dukto.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ IDI_ICON1 ICON DISCARDABLE "dukto.ico"

#include <windows.h>

#define VER_FILEVERSION 4,9,8,0
#define VER_FILEVERSION_STR "4.9.8.0\0"
#define VER_FILEVERSION 6,0,0,0
#define VER_FILEVERSION_STR "6.0.0.0\0"

#define VER_PRODUCTVERSION 4,9,8,0
#define VER_PRODUCTVERSION_STR "4.9\0"
#define VER_PRODUCTVERSION 6,0,0,0
#define VER_PRODUCTVERSION_STR "6.0\0"

#define VER_COMPANYNAME_STR "msec.it"
#define VER_FILEDESCRIPTION_STR "Dukto R5"
#define VER_INTERNALNAME_STR "Dukto R5"
#define VER_LEGALCOPYRIGHT_STR "Copyright � 2010 Emanuele Colombo"
#define VER_FILEDESCRIPTION_STR "Dukto R6"
#define VER_INTERNALNAME_STR "Dukto R6"
#define VER_LEGALCOPYRIGHT_STR "Copyright � 2013 Emanuele Colombo"
#define VER_LEGALTRADEMARKS1_STR "All Rights Reserved"
#define VER_LEGALTRADEMARKS2_STR VER_LEGALTRADEMARKS1_STR
#define VER_ORIGINALFILENAME_STR "dukto.exe"
#define VER_PRODUCTNAME_STR "Dukto R5"
#define VER_PRODUCTNAME_STR "Dukto R6"

#define VER_COMPANYDOMAIN_STR "msec.it"

Expand Down
158 changes: 134 additions & 24 deletions duktoprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DuktoProtocol::DuktoProtocol()

mIsSending = false;
mIsReceiving = false;
mSendingScreen = false;
}

DuktoProtocol::~DuktoProtocol()
Expand Down Expand Up @@ -144,10 +145,13 @@ void DuktoProtocol::newUdpData()
{
while (mSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(mSocket->pendingDatagramSize());
const int maxLength = 65536; // Theoretical max length in IPv4
datagram.resize(maxLength);
// datagram.resize(mSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
mSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
int size = mSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
datagram.resize(size);
handleMessage(datagram, sender);
}
}
Expand All @@ -162,7 +166,7 @@ void DuktoProtocol::handleMessage(QByteArray &data, QHostAddress &sender)
case 0x02: // HELLO (unicast)
data.remove(0, 1);
if (data != getSystemSignature()) {
mPeers[sender.toString()] = Peer(sender, data, DEFAULT_UDP_PORT);
mPeers[sender.toString()] = Peer(sender, QString::fromUtf8(data), DEFAULT_UDP_PORT);
if (msgtype == 0x01) sayHello(sender, DEFAULT_UDP_PORT);
emit peerListAdded(mPeers[sender.toString()]);
}
Expand All @@ -179,7 +183,7 @@ void DuktoProtocol::handleMessage(QByteArray &data, QHostAddress &sender)
qint16 port = *((qint16*) data.constData());
data.remove(0, 2);
if (data != getSystemSignature()) {
mPeers[sender.toString()] = Peer(sender, data, port);
mPeers[sender.toString()] = Peer(sender, QString::fromUtf8(data), port);
if (msgtype == 0x04) sayHello(sender, port);
emit peerListAdded(mPeers[sender.toString()]);
}
Expand Down Expand Up @@ -233,6 +237,7 @@ void DuktoProtocol::newIncomingConnection()
mRootFolderName = "";
mRootFolderRenamed = "";
mReceivingText = false;
mRecvStatus = FILENAME;

// -- Lettura header generale --
// Numero entità da ricevere
Expand All @@ -248,31 +253,38 @@ void DuktoProtocol::newIncomingConnection()
// Processo di lettura principale
void DuktoProtocol::readNewData()
{
// Temporanea disconnessione per evitare di
// ricevere altri segnali mentre ne sto già gestendo uno
disconnect(mCurrentSocket, SIGNAL(readyRead()), this, SLOT(readNewData()));

// Fino a che ci sono dati da leggere
while (mCurrentSocket->bytesAvailable() > 0)
{

// Verifico se devo leggere un header
if (mElementSize == -1)
// In base allo stato in cui mi trovo leggo quello che mi aspetto
switch (mRecvStatus)
{

case FILENAME:
{
// Lettura nome
char c;
while (1) {
bool ret = mCurrentSocket->getChar(&c);
if (!ret) return;
if (c == '\0') break;
int ret = mCurrentSocket->read(&c, sizeof(c));
if (ret < 1) return;
if (c == '\0')
{
mRecvStatus = FILESIZE;
break;
}
mPartialName.append(c);
}
QString name = QString::fromUtf8(mPartialName);
mPartialName.clear();
}
break;

// Lettura dimensioni
case FILESIZE:
{
if (!(mCurrentSocket->bytesAvailable() >= sizeof(qint64))) return;
mCurrentSocket->read((char*) &mElementSize, sizeof(qint64));
mElementReceivedData = 0;
QString name = QString::fromUtf8(mPartialName);
mPartialName.clear();

// Se l'elemento corrente è una cartella, la creo e passo all'elemento successivo
if (mElementSize == -1)
Expand Down Expand Up @@ -301,8 +313,30 @@ void DuktoProtocol::readNewData()

// Creo la cartella
QDir dir(".");
dir.mkpath(name);
continue;
bool ret = dir.mkpath(name);
if (!ret)
{
emit receiveFileCancelled();
// Chiusura socket
if (mCurrentSocket)
{
mCurrentSocket->disconnect();
mCurrentSocket->disconnectFromHost();
mCurrentSocket->close();
mCurrentSocket->deleteLater();
mCurrentSocket = NULL;
}

// Rilascio memoria
delete mReceivedFiles;
mReceivedFiles = NULL;

// Impostazione stato
mIsReceiving = false;
return;
}
mRecvStatus = FILENAME;
break;
}

// Potrebbe essere un invio di testo
Expand Down Expand Up @@ -331,12 +365,37 @@ void DuktoProtocol::readNewData()
}
mReceivedFiles->append(name);
mCurrentFile = new QFile(name);
mCurrentFile->open(QIODevice::WriteOnly);
mReceivingText = false;
bool ret = mCurrentFile->open(QIODevice::WriteOnly);
if (!ret)
{
emit receiveFileCancelled();
// Chiusura socket
if (mCurrentSocket)
{
mCurrentSocket->disconnect();
mCurrentSocket->disconnectFromHost();
mCurrentSocket->close();
mCurrentSocket->deleteLater();
mCurrentSocket = NULL;
}

// Rilascio memoria
delete mReceivedFiles;
mReceivedFiles = NULL;

// Impostazione stato
mIsReceiving = false;
return;
}
mReceivingText = false;
}
mRecvStatus = DATA;
}
break;


case DATA:
{
// Provo a leggere quanto mi serve per finire il file corrente
// (o per svuotare il buffer dei dati ricevuti)
qint64 s = (mCurrentSocket->bytesAvailable() > (mElementSize - mElementReceivedData))
Expand All @@ -363,16 +422,18 @@ void DuktoProtocol::readNewData()
mCurrentFile->deleteLater();
mCurrentFile = NULL;
}
mRecvStatus = FILENAME;
}
}
break;

// Riabilitazione segnale
connect(mCurrentSocket, SIGNAL(readyRead()), this, SLOT(readNewData()), Qt::DirectConnection);
}
}
}

void DuktoProtocol::closedConnectionTmp()
{
QTimer::singleShot(100, this, SLOT(closedConnection()));
QTimer::singleShot(500, this, SLOT(closedConnection()));
}

// Chiusura della connessione TCP in ricezione
Expand Down Expand Up @@ -471,6 +532,34 @@ void DuktoProtocol::sendText(QString ipDest, qint16 port, QString text)
mCurrentSocket->connectToHost(ipDest, port);
}

void DuktoProtocol::sendScreen(QString ipDest, qint16 port, QString path)
{
// Check for default port
if (port == 0) port = DEFAULT_TCP_PORT;

// Verifica altre attività in corso
if (mIsReceiving || mIsSending) return;
mIsSending = true;

// File da inviare
QStringList files;
files.append(path);
mFilesToSend = expandTree(files);
mFileCounter = 0;
mSendingScreen = true;

// Connessione al destinatario
mCurrentSocket = new QTcpSocket(this);

// Gestione segnali
connect(mCurrentSocket, SIGNAL(connected()), this, SLOT(sendMetaData()), Qt::DirectConnection);
connect(mCurrentSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(sendConnectError(QAbstractSocket::SocketError)), Qt::DirectConnection);
connect(mCurrentSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(sendData(qint64)), Qt::DirectConnection);

// Connessione
mCurrentSocket->connectToHost(ipDest, port);
}

void DuktoProtocol::sendMetaData()
{
// Impostazione buffer di invio
Expand Down Expand Up @@ -683,7 +772,18 @@ QByteArray DuktoProtocol::nextElementHeader()
}

// Nome elemento
QString name = fullname;
QString name;

// Verifico se si tratta di un invio screen
if (mSendingScreen) {

name = "Screenshot.jpg";
mSendingScreen = false;
}
else
name = fullname;

// Aggiunta nome file all'header
name.replace(mBasePath + "/", "");
header.append(name.toUtf8() + '\0');

Expand Down Expand Up @@ -751,3 +851,13 @@ void DuktoProtocol::abortCurrentTransfer()
closeCurrentTransfer(true);
emit sendFileAborted();
}

// Aggiorna il buddy name dell'utente locale
void DuktoProtocol::updateBuddyName()
{
// Invio pacchetto di disconnessione
sayGoodbye();

// Invio pacchetto di annuncio con il nuovo nome
sayHello(QHostAddress::Broadcast, true);
}
8 changes: 8 additions & 0 deletions duktoprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class DuktoProtocol : public QObject
inline QHash<QString, Peer>& getPeers() { return mPeers; }
void sendFile(QString ipDest, qint16 port, QStringList files);
void sendText(QString ipDest, qint16 port, QString text);
void sendScreen(QString ipDest, qint16 port, QString path);
inline bool isBusy() { return mIsSending || mIsReceiving; }
void abortCurrentTransfer();
void updateBuddyName();

public slots:
void newUdpData();
Expand Down Expand Up @@ -103,6 +105,7 @@ public slots:
qint64 mSentBuffer; // Quantità di dati rimanenti nel buffer di trasmissione
QString mBasePath; // Percorso base per l'invio di file e cartelle
QString mTextToSend; // Testo da inviare (in caso di invio testuale)
bool mSendingScreen; // Flag che indica se si sta inviando uno screenshot

// Receive members
qint64 mElementsToReceiveCount; // Numero di elementi da ricevere
Expand All @@ -115,6 +118,11 @@ public slots:
QByteArray mTextToReceive; // Testo ricevuto in caso di invio testo
bool mReceivingText; // Ricezione di testo in corso
QByteArray mPartialName; // Nome prossimo file letto solo in parte
enum RecvStatus {
FILENAME,
FILESIZE,
DATA
} mRecvStatus;

};

Expand Down
4 changes: 3 additions & 1 deletion duktowindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ DuktoWindow::DuktoWindow(QWidget *parent) :
{
// Configure window
setAcceptDrops(true);
setWindowTitle("Dukto R5");
setWindowTitle("Dukto");
#ifndef Q_WS_S60
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
setMaximumSize(350, 5000);
setMinimumSize(350, 500);
#endif
setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);

// Taskbar integration with Win7
Expand Down
Loading

0 comments on commit 41e68f2

Please sign in to comment.