Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
abdularis committed May 27, 2017
2 parents 9352d2e + 3171b86 commit 3332ac8
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 25 deletions.
8 changes: 8 additions & 0 deletions packaging/linux/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: LANShare
Version: 1.2.0-1
License: GPL3
Architecture: amd64
Maintainer: Abdul Aris R. <abdularisrahmanudin10@gmail.com>
Section: default
Priority: extra
Description: LANShare is a simple open-source cross platform application that let you transfer files and/or folder through local area network(LAN) easily. You can send and receive files and folder within LAN without any additional configuration needed on each platform. It can runs on most version of Windows(XP or later) and Linux(Debian, Ubuntu, Fedora, etc).
14 changes: 14 additions & 0 deletions packaging/linux/debian/LANShare.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Desktop Entry]
Encoding=UTF-8
Version=1.2.0
Type=Application
Name=LANShare
Categories=System
GenericName=LAN File Transfer
Comment=Local Area Network (LAN) File Transfer
Icon=/usr/share/pixmaps/lanshare-icon.png
Path=/usr/lib/LANShare
Exec=/usr/lib/LANShare/LANShare.sh
StartupNotify=false

Name[en_US]=LANShare.d.desktop
4 changes: 4 additions & 0 deletions packaging/linux/debian/LANShare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export LD_LIBRARY_PATH=./
./LANShare -style gtk2
Binary file added packaging/linux/debian/lanshare-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packaging/windows/LANShare_setup_script.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "LANShare"
#define MyAppVersion "1.1.0"
#define MyAppExeName "LANShare.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{A09C1E15-344D-47AF-9767-B8479736B5E8}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
DefaultDirName={pf}\{#MyAppName}
DisableProgramGroupPage=yes
LicenseFile=..\..\src\text\gpl-3.0.txt
InfoBeforeFile=info_before.txt
InfoAfterFile=info_after.txt
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "bin\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

1 change: 1 addition & 0 deletions packaging/windows/info_after.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thanks for using our application.
3 changes: 3 additions & 0 deletions packaging/windows/info_before.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LANShare is a simple open-source cross platform application that let you transfer files and/or folder through local area network(LAN) easily.
You can send and receive files and folder within LAN without any additional configuration needed on each platform.
It can runs on most version of Windows(XP or later) and Linux(Debian, Ubuntu, Fedora, etc).
49 changes: 40 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <QToolButton>
#include <QCloseEvent>
#include <QtDebug>
#include <QListView>
#include <QTreeView>

#include "mainwindow.h"
#include "ui_mainwindow.h"
Expand Down Expand Up @@ -155,9 +157,9 @@ void MainWindow::connectSignals()
this, &MainWindow::onReceiverTableSelectionChanged);
}

void MainWindow::sendFile(const QString& folderName, const QString &fileName, const Device &receiver)
void MainWindow::sendFile(const QString& folderName, const QString &filePath, const Device &receiver)
{
Sender* sender = new Sender(receiver, folderName, fileName, this);
Sender* sender = new Sender(receiver, folderName, filePath, this);
sender->start();
mSenderModel->insertTransfer(sender);
QModelIndex progressIdx = mSenderModel->index(0, (int)TransferTableModel::Column::Progress);
Expand All @@ -180,6 +182,10 @@ void MainWindow::selectReceiversAndSendTheFiles(QVector<QPair<QString, QString>
for (Device receiver : receivers) {
if (receiver.isValid()) {

/*
* Memastikan bahwa device/kompuer ini terdaftar di penerima
* Just to make sure.
*/
mBroadcaster->sendBroadcast();
for (auto p : dirNameAndFullPath) {
sendFile(p.first, p.second, receiver);
Expand All @@ -197,7 +203,7 @@ void MainWindow::onShowMainWindowTriggered()

void MainWindow::onSendFilesActionTriggered()
{
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select files"), QDir::homePath());
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Select files"));
if (fileNames.size() <= 0)
return;

Expand All @@ -210,13 +216,38 @@ void MainWindow::onSendFilesActionTriggered()

void MainWindow::onSendFolderActionTriggered()
{
QString dirName = QFileDialog::getExistingDirectory(this, tr("Select Folder"), QDir::homePath(),
QFileDialog::ShowDirsOnly);
if (dirName.isEmpty())
QStringList dirs;
QFileDialog fDialog(this);
fDialog.setFileMode(QFileDialog::Directory);
fDialog.setOption(QFileDialog::ShowDirsOnly);

/*
* Enable multiple foder selection
*/
QListView* lView = fDialog.findChild<QListView*>("listView");
if (lView)
lView->setSelectionMode(QAbstractItemView::ExtendedSelection);
QTreeView* tView = fDialog.findChild<QTreeView*>("treeView");
if (tView)
tView->setSelectionMode(QAbstractItemView::ExtendedSelection);

fDialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (!fDialog.exec()) {
return;
}

QDir dir(dirName);
QVector< QPair<QString, QString> > pairs = Util::getRelativeDirNameAndFullFilePath(dir, dir.dirName());
/*
* Iterate through all selected folders
*/
QVector< QPair<QString, QString> > pairs;
dirs = fDialog.selectedFiles();
for (auto dirName : dirs) {

QDir dir(dirName);
QVector< QPair<QString, QString> > ps =
Util::getRelativeDirNameAndFullFilePath(dir, dir.dirName());
pairs.append(ps);
}

selectReceiversAndSendTheFiles(pairs);
}
Expand Down Expand Up @@ -584,7 +615,7 @@ void MainWindow::setupActions()
connect(mShowMainWindowAction, &QAction::triggered, this, &MainWindow::onShowMainWindowTriggered);
mSendFilesAction = new QAction(QIcon(":/img/file.png"), tr("Send files..."), this);
connect(mSendFilesAction, &QAction::triggered, this, &MainWindow::onSendFilesActionTriggered);
mSendFolderAction = new QAction(QIcon(":/img/folder.png"), tr("Send folder..."), this);
mSendFolderAction = new QAction(QIcon(":/img/folder.png"), tr("Send folders..."), this);
connect(mSendFolderAction, &QAction::triggered, this, &MainWindow::onSendFolderActionTriggered);
mSettingsAction = new QAction(QIcon(":/img/settings.png"), tr("Settings"), this);
connect(mSettingsAction, &QAction::triggered, this, &MainWindow::onSettingsActionTriggered);
Expand Down
31 changes: 22 additions & 9 deletions src/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QJsonDocument>
#include <QDir>

#include "util.h"
#include "receiver.h"
#include "settings.h"

Expand Down Expand Up @@ -75,24 +76,36 @@ void Receiver::processHeaderPacket(QByteArray& data)
mFileSize = obj.value("size").toVariant().value<qint64>();
mInfo->setDataSize(mFileSize);

QString folderName = Settings::instance()->getDownloadDir() +
QDir::separator() + obj.value("folder").toString();
QString fileName = folderName +
QDir::separator() + obj.value("name").toString();
mFile = new QFile(fileName, this);
mInfo->setFilePath(fileName);
QString fileName = obj.value("name").toString();
QString folderName = obj.value("folder").toString();
QString dstFolderPath = Settings::instance()->getDownloadDir();
if (!folderName.isEmpty())
dstFolderPath = dstFolderPath + QDir::separator() + folderName;

QDir dir(folderName);
/*
* Jika folder didalam Download Dir tidak ada maka buat folder tsb.
*/
QDir dir(dstFolderPath);
if (!dir.exists()) {
dir.mkpath(folderName);
dir.mkpath(dstFolderPath);
}

QString dstFilePath = dstFolderPath + QDir::separator() + fileName;
/*
* Jika opsi overwrite tdk dicentang maka rename file agar tdk tertindih
*/
if (!Settings::instance()->getReplaceExistingFile()) {
dstFilePath = Util::getCheckedFilePath(fileName, dstFolderPath);
}

mInfo->setFilePath(dstFilePath);
mFile = new QFile(dstFilePath, this);
if (mFile->open(QIODevice::WriteOnly)) {
mInfo->setState(TransferState::Transfering);
emit mInfo->fileOpened();
}
else {
emit mInfo->errorOcurred(tr("Failed to create ") + fileName);
emit mInfo->errorOcurred(tr("Failed to write ") + dstFilePath);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/receiverselectordialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>290</width>
<width>380</width>
<height>300</height>
</rect>
</property>
Expand All @@ -18,13 +18,13 @@
</property>
<property name="minimumSize">
<size>
<width>290</width>
<width>380</width>
<height>300</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>290</width>
<width>380</width>
<height>300</height>
</size>
</property>
Expand Down
11 changes: 11 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ void Settings::setDownloadDir(const QString& dir)
mDownloadDir = dir;
}

void Settings::setReplaceExistingFile(bool replace)
{
mReplaceExistingFile = replace;
}

void Settings::loadSettings()
{
QSettings settings(SETTINGS_FILE);
Expand All @@ -99,6 +104,7 @@ void Settings::loadSettings()
}

mBCInterval = settings.value("BroadcastInterval", DefaultBroadcastInterval).value<quint16>();
mReplaceExistingFile = settings.value("ReplaceExistingFile", false).toBool();
}

QString Settings::getDefaultDownloadPath()
Expand All @@ -120,6 +126,7 @@ void Settings::saveSettings()
settings.setValue("FileBufferSize", mFileBuffSize);
settings.setValue("DownloadDir", mDownloadDir);
settings.setValue("BroadcastInterval", mBCInterval);
settings.setValue("ReplaceExistingFile", mReplaceExistingFile);
}

void Settings::reset()
Expand Down Expand Up @@ -177,4 +184,8 @@ QHostAddress Settings::getDeviceAddress() const
return mThisDevice.getAddress();
}

bool Settings::getReplaceExistingFile() const
{
return mReplaceExistingFile;
}

5 changes: 4 additions & 1 deletion src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define PROGRAM_NAME "LANShare"
#define PROGRAM_DESC "A simple program that let you transfer files over local area network (LAN) easily."
#define PROGRAM_X_VER 1
#define PROGRAM_Y_VER 1
#define PROGRAM_Y_VER 2
#define PROGRAM_Z_VER 0
#define SETTINGS_FILE "LANSConfig"

Expand All @@ -57,13 +57,15 @@ class Settings
QString getDeviceId() const;
QString getDeviceName() const;
QHostAddress getDeviceAddress() const;
bool getReplaceExistingFile() const;

void setDeviceName(const QString& name);
void setBroadcastPort(quint16 port);
void setTransferPort(quint16 port);
void setBroadcastInterval(quint16 interval);
void setFileBufferSize(qint32 size);
void setDownloadDir(const QString& dir);
void setReplaceExistingFile(bool replace);

void saveSettings();
void reset();
Expand All @@ -80,6 +82,7 @@ class Settings
quint16 mBCInterval;
qint32 mFileBuffSize;
QString mDownloadDir;
bool mReplaceExistingFile;

static Settings* obj;
};
Expand Down
2 changes: 2 additions & 0 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void SettingsDialog::onSaveClicked()
set->setDeviceName(ui->deviceNameLineEdit->text());
set->setDownloadDir(ui->downDirlineEdit->text());
set->setBroadcastInterval(ui->bcIntervalSpinBox->value());
set->setReplaceExistingFile(ui->overwriteCheckBox->isChecked());

set->saveSettings();

Expand Down Expand Up @@ -91,4 +92,5 @@ void SettingsDialog::assign()
ui->transferPortSpinBox->setValue(sets->getTransferPort());
ui->buffSizeSpinBox->setValue(sets->getFileBufferSize() / 1024);
ui->bcIntervalSpinBox->setValue(sets->getBroadcastInterval());
ui->overwriteCheckBox->setChecked(sets->getReplaceExistingFile());
}
14 changes: 11 additions & 3 deletions src/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,17 @@
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="title">
<string>Behavior</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="overwriteCheckBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Overwrite existing file</string>
</property>
Expand All @@ -248,13 +251,19 @@
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_10">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Max. Current Transfers:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
Expand Down Expand Up @@ -373,7 +382,6 @@
</item>
</layout>
<zorder></zorder>
<zorder></zorder>
</widget>
</item>
<item>
Expand Down
Loading

0 comments on commit 3332ac8

Please sign in to comment.