Commit 8ffa3c91 authored by DreamSourceLab's avatar DreamSourceLab

add support for path with chinese characters

parent 4348c2a8
......@@ -357,10 +357,14 @@ install(FILES res/DSLogicPro.fw DESTINATION bin/res/)
install(FILES res/DSLogicPro.bin DESTINATION bin/res/)
install(FILES res/DSCope.fw DESTINATION bin/res/)
install(FILES res/DSCope.bin DESTINATION bin/res/)
install(FILES res/DSLogic_ini.dsc DESTINATION bin/res/)
install(FILES res/DSLogic_ini.dsc.bak DESTINATION bin/res/)
install(FILES res/DSCope_ini.dsc DESTINATION bin/res/)
install(FILES res/DSCope_ini.dsc.bak DESTINATION bin/res/)
install(FILES res/DSLogic0.dsc DESTINATION bin/res/)
install(FILES res/DSLogic0.def.dsc DESTINATION bin/res/)
install(FILES res/DSLogic1.dsc DESTINATION bin/res/)
install(FILES res/DSLogic1.def.dsc DESTINATION bin/res/)
install(FILES res/DSLogic2.dsc DESTINATION bin/res/)
install(FILES res/DSLogic2.def.dsc DESTINATION bin/res/)
install(FILES res/DSCope1.dsc DESTINATION bin/res/)
install(FILES res/DSCope1.def.dsc DESTINATION bin/res/)
#===============================================================================
#= Packaging (handled by CPack)
......
......@@ -64,7 +64,7 @@ void Device::release()
sr_dev_close(_sdi);
}
std::string Device::format_device_title() const
QString Device::format_device_title() const
{
ostringstream s;
......@@ -86,7 +86,7 @@ std::string Device::format_device_title() const
if (_sdi->version && _sdi->version[0])
s << _sdi->version;
return s.str();
return QString::fromStdString(s.str());
}
bool Device::is_trigger_enabled() const
......
......@@ -38,7 +38,7 @@ public:
void release();
std::string format_device_title() const;
QString format_device_title() const;
bool is_trigger_enabled() const;
......
......@@ -59,7 +59,7 @@ public:
SigSession* owner() const;
virtual std::string format_device_title() const = 0;
virtual QString format_device_title() const = 0;
GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key);
......
......@@ -32,19 +32,19 @@ using std::string;
namespace pv {
namespace device {
File::File(const std::string path) :
File::File(QString path) :
_path(path)
{
}
std::string File::format_device_title() const
QString File::format_device_title() const
{
return boost::filesystem::path(_path).filename().string();
return _path;
}
File* File::create(const string &name)
File* File::create(QString name)
{
if (sr_session_load(name.c_str()) == SR_OK) {
if (sr_session_load(name.toLocal8Bit().data()) == SR_OK) {
GSList *devlist = NULL;
sr_session_dev_list(&devlist);
sr_session_destroy();
......
......@@ -32,16 +32,16 @@ namespace device {
class File : public DevInst
{
protected:
File(const std::string path);
File(QString path);
public:
static File* create(const std::string &name);
static File* create(QString name);
public:
std::string format_device_title() const;
QString format_device_title() const;
protected:
const std::string _path;
const QString _path;
};
} // device
......
......@@ -34,7 +34,7 @@ using std::string;
namespace pv {
namespace device {
InputFile::InputFile(const std::string &path) :
InputFile::InputFile(QString path) :
File(path),
_input(NULL)
{
......@@ -71,8 +71,7 @@ void InputFile::release()
_input = NULL;
}
sr_input_format* InputFile::determine_input_file_format(
const string &filename)
sr_input_format* InputFile::determine_input_file_format(const QString filename)
{
int i;
......@@ -85,7 +84,7 @@ sr_input_format* InputFile::determine_input_file_format(
/* Otherwise, try to find an input module that can handle this file. */
for (i = 0; inputs[i]; i++) {
if (inputs[i]->format_match(filename.c_str()))
if (inputs[i]->format_match(filename.toLocal8Bit().data()))
break;
}
......@@ -98,19 +97,19 @@ sr_input_format* InputFile::determine_input_file_format(
return inputs[i];
}
sr_input* InputFile::load_input_file_format(const string &filename,
sr_input* InputFile::load_input_file_format(const QString filename,
sr_input_format *format)
{
struct stat st;
sr_input *in;
if (!format && !(format =
determine_input_file_format(filename.c_str()))) {
determine_input_file_format(filename))) {
/* The exact cause was already logged. */
throw tr("Failed to load file");
}
if (stat(filename.c_str(), &st) == -1)
if (stat(filename.toLocal8Bit().data(), &st) == -1)
throw tr("Failed to load file");
/* Initialize the input module. */
......@@ -121,7 +120,7 @@ sr_input* InputFile::load_input_file_format(const string &filename,
in->format = format;
in->param = NULL;
if (in->format->init &&
in->format->init(in, filename.c_str()) != SR_OK) {
in->format->init(in, filename.toLocal8Bit().data()) != SR_OK) {
throw tr("Failed to load file");
}
......@@ -137,7 +136,7 @@ void InputFile::run()
assert(_input);
assert(_input->format);
assert(_input->format->loadfile);
_input->format->loadfile(_input, _path.c_str());
_input->format->loadfile(_input, _path.toLocal8Bit().data());
}
} // device
......
......@@ -35,7 +35,7 @@ namespace device {
class InputFile : public File
{
public:
InputFile(const std::string &path);
InputFile(QString path);
sr_dev_inst* dev_inst() const;
......@@ -55,9 +55,9 @@ private:
* or NULL if no input format was selected or auto-detected.
*/
static sr_input_format* determine_input_file_format(
const std::string &filename);
const QString filename);
static sr_input* load_input_file_format(const std::string &filename,
static sr_input* load_input_file_format(const QString filename,
sr_input_format *format);
private:
sr_input *_input;
......
......@@ -26,7 +26,7 @@
namespace pv {
namespace device {
SessionFile::SessionFile(const std::string &path) :
SessionFile::SessionFile(QString path) :
File(path),
_sdi(NULL)
{
......@@ -41,7 +41,7 @@ void SessionFile::use(SigSession *owner) throw(QString)
{
assert(!_sdi);
if (sr_session_load(_path.c_str()) != SR_OK)
if (sr_session_load(_path.toLocal8Bit().data()) != SR_OK)
throw tr("Failed to open file.\n");
GSList *devlist = NULL;
......
......@@ -30,7 +30,7 @@ namespace device {
class SessionFile : public File
{
public:
SessionFile(const std::string &path);
SessionFile(QString path);
sr_dev_inst* dev_inst() const;
......
......@@ -106,8 +106,9 @@ std::list<boost::shared_ptr<device::DevInst> > DeviceManager::driver_scan(
QDir dir(QCoreApplication::applicationDirPath());
if (!dir.cd("res"))
return driver_devices;
std::string str = dir.absolutePath().toStdString() + "/";
strcpy(config_path, str.c_str());
QString str = dir.absolutePath() + "/";
QString str_utf8 = QString::fromLocal8Bit(str.toLocal8Bit());
strcpy(config_path, str_utf8.toUtf8().data());
}
// Do the scan
......
......@@ -318,7 +318,7 @@ void MainWindow::update_device_list()
if (strcmp(selected_device->dev_inst()->driver->name, "demo") != 0) {
_logo_bar->dsl_connected(true);
QString ses_name = config_path +
QString::fromLocal8Bit(selected_device->dev_inst()->driver->name) +
QString::fromUtf8(selected_device->dev_inst()->driver->name) +
QString::number(selected_device->dev_inst()->mode) +
".dsc";
load_session(ses_name);
......@@ -336,7 +336,8 @@ void MainWindow::reload()
void MainWindow::load_file(QString file_name)
{
try {
_session.set_file(file_name.toStdString());
//_session.set_file(file_name.toStdString());
_session.set_file(file_name);
} catch(QString e) {
show_session_error(tr("Failed to load ") + file_name, e);
_session.set_default_device(boost::bind(&MainWindow::session_error, this,
......@@ -571,7 +572,7 @@ void MainWindow::on_save()
bool MainWindow::load_session(QString name)
{
QFile sessionFile(name.toStdString().c_str());
QFile sessionFile(name);
if (!sessionFile.open(QIODevice::ReadOnly)) {
QMessageBox msg(this);
msg.setText(tr("File Error"));
......@@ -582,8 +583,8 @@ bool MainWindow::load_session(QString name)
return false;
}
QByteArray sessionData = sessionFile.readAll();
QJsonDocument sessionDoc = QJsonDocument::fromJson(sessionData);
QString sessionData = QString::fromUtf8(sessionFile.readAll());
QJsonDocument sessionDoc = QJsonDocument::fromJson(sessionData.toUtf8());
QJsonObject sessionObj = sessionDoc.object();
// check device and mode
......@@ -617,7 +618,7 @@ bool MainWindow::load_session(QString name)
else if (info->datatype == SR_T_FLOAT)
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble()));
else if (info->datatype == SR_T_CHAR)
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toLocal8Bit()));
_session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8()));
}
}
_sampling_bar->update_record_length();
......@@ -680,8 +681,8 @@ bool MainWindow::load_session(QString name)
bool MainWindow::store_session(QString name)
{
QFile sessionFile(name.toStdString().c_str());
if (!sessionFile.open(QIODevice::WriteOnly)) {
QFile sessionFile(name);
if (!sessionFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox msg(this);
msg.setText(tr("File Error"));
msg.setInformativeText(tr("Couldn't open session file to write!"));
......@@ -690,6 +691,9 @@ bool MainWindow::store_session(QString name)
msg.exec();
return false;
}
QTextStream outStream(&sessionFile);
outStream.setCodec("UTF-8");
outStream.setGenerateByteOrderMark(true);
GVariant *gvar_opts;
GVariant *gvar;
......@@ -748,8 +752,11 @@ bool MainWindow::store_session(QString name)
sessionVar["trigger"] = _trigger_widget->get_session();
}
QJsonDocument sessionDoc(sessionVar);
sessionFile.write(sessionDoc.toJson());
//sessionFile.write(QString::fromUtf8(sessionDoc.toJson()));
outStream << QString::fromUtf8(sessionDoc.toJson());
sessionFile.close();
return true;
}
......
......@@ -66,7 +66,7 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) :
if(sr_config_list(_sdi->driver, _sdi, NULL, key, &gvar_list) != SR_OK)
gvar_list = NULL;
const QString name(info->name);
const QString name(info->label);
switch(key)
{
......@@ -194,11 +194,11 @@ QString DeviceOptions::print_gvariant(GVariant *const gvar)
QString s;
if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s")))
s = QString(g_variant_get_string(gvar, NULL));
s = QString::fromUtf8(g_variant_get_string(gvar, NULL));
else
{
gchar *const text = g_variant_print(gvar, FALSE);
s = QString(text);
s = QString::fromUtf8(text);
g_free(text);
}
......
......@@ -47,7 +47,7 @@ QWidget* String::get_widget(QWidget *parent, bool auto_commit)
_line_edit = new QLineEdit(parent);
_line_edit->setText(QString::fromUtf8(
g_variant_get_string(value, NULL)));
g_variant_get_string(value, NULL)));
g_variant_unref(value);
if (auto_commit)
......@@ -65,7 +65,7 @@ void String::commit()
return;
QByteArray ba = _line_edit->text().toLocal8Bit();
_setter(g_variant_new_string(ba.data()));
_setter(g_variant_new_string(ba.data()));
}
void String::on_text_edited(const QString&)
......
......@@ -158,7 +158,8 @@ void SigSession::set_device(boost::shared_ptr<device::DevInst> dev_inst) throw(Q
}
}
void SigSession::set_file(const string &name) throw(QString)
void SigSession::set_file(QString name) throw(QString)
{
// Deslect the old device, because file type detection in File::create
// destorys the old session inside libsigrok.
......@@ -176,7 +177,7 @@ void SigSession::set_file(const string &name) throw(QString)
}
}
void SigSession::save_file(const std::string &name){
void SigSession::save_file(const QString name){
const deque< boost::shared_ptr<pv::data::LogicSnapshot> > &snapshots =
_logic_data->get_snapshots();
if (snapshots.empty())
......@@ -185,7 +186,7 @@ void SigSession::save_file(const std::string &name){
const boost::shared_ptr<pv::data::LogicSnapshot> &snapshot =
snapshots.front();
sr_session_save(name.c_str(), _dev_inst->dev_inst(),
sr_session_save(name.toLocal8Bit().data(), _dev_inst->dev_inst(),
(unsigned char*)snapshot->get_data(),
snapshot->unit_size(),
snapshot->get_sample_count());
......@@ -213,7 +214,7 @@ void SigSession::cancelSaveFile(){
saveFileThreadRunning = false;
}
void SigSession::export_file(const std::string &name, QWidget* parent, const std::string &ext){
void SigSession::export_file(const QString name, QWidget* parent, const QString ext){
boost::shared_ptr<pv::data::Snapshot> snapshot;
int channel_type;
......@@ -240,7 +241,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
while(*supportedModules){
if(*supportedModules == NULL)
break;
if(!strcmp((*supportedModules)->id, ext.c_str())){
if(!strcmp((*supportedModules)->id, ext.toLocal8Bit().data())){
outModule = *supportedModules;
break;
}
......@@ -251,7 +252,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
GHashTable *params = g_hash_table_new(g_str_hash, g_str_equal);
GVariant* filenameGVariant = g_variant_new_string(name.c_str());
GVariant* filenameGVariant = g_variant_new_bytestring(name.toLocal8Bit().data());
g_hash_table_insert(params, (char*)"filename", filenameGVariant);
GVariant* typeGVariant = g_variant_new_int16(channel_type);
g_hash_table_insert(params, (char*)"type", typeGVariant);
......@@ -270,9 +271,11 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
output.param = NULL;
if(outModule->init)
outModule->init(&output, params);
QFile file(name.c_str());
QFile file(name);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(true);
QFuture<void> future;
if (_dev_inst->dev_inst()->mode == LOGIC) {
future = QtConcurrent::run([&]{
......@@ -294,7 +297,7 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
p.payload = &lp;
outModule->receive(&output, &p, &data_out);
if(data_out){
out << (char*) data_out->str;
out << QString::fromUtf8((char*) data_out->str);
g_string_free(data_out,TRUE);
}
emit progressSaveFileValueChanged(i*100/numsamples);
......@@ -333,8 +336,8 @@ void SigSession::export_file(const std::string &name, QWidget* parent, const std
QFutureWatcher<void> watcher;
Qt::WindowFlags flags = Qt::CustomizeWindowHint;
QProgressDialog dlg(QString::fromUtf8("Exporting data... It can take a while."),
QString::fromUtf8("Cancel"),0,100,parent,flags);
QProgressDialog dlg(tr("Exporting data... It can take a while."),
tr("Cancel"),0,100,parent,flags);
dlg.setWindowModality(Qt::WindowModal);
watcher.setFuture(future);
connect(&watcher,SIGNAL(finished()),&dlg,SLOT(cancel()));
......@@ -832,9 +835,9 @@ void SigSession::refresh(int holdtime)
_analog_data->clear();
_cur_analog_snapshot.reset();
}
data_updated();
_data_lock = true;
_refresh_timer.start(holdtime);
data_updated();
}
void SigSession::data_unlock()
......
......@@ -114,13 +114,13 @@ public:
void set_device(boost::shared_ptr<device::DevInst> dev_inst)
throw(QString);
void set_file(const std::string &name)
void set_file(QString name)
throw(QString);
void save_file(const std::string &name);
void save_file(const QString name);
void set_default_device(boost::function<void (const QString)> error_handler);
void export_file(const std::string &name, QWidget* parent, const std::string &ext);
void export_file(const QString name, QWidget* parent, const QString ext);
void set_default_device();
......
......@@ -182,7 +182,7 @@ void FileBar::on_actionExport_triggered(){
QString ext = list.first();
if(f.suffix().compare(ext))
file_name+=tr(".")+ext;
_session.export_file(file_name.toStdString(), this, ext.toStdString());
_session.export_file(file_name, this, ext);
}
}
}
......@@ -215,7 +215,7 @@ void FileBar::on_actionSave_triggered()
QFileInfo f(file_name);
if(f.suffix().compare("dsl"))
file_name.append(tr(".dsl"));
_session.save_file(file_name.toStdString());
_session.save_file(file_name);
}
}
}
......
......@@ -173,7 +173,7 @@ void SamplingBar::set_device_list(
BOOST_FOREACH (shared_ptr<pv::device::DevInst> dev_inst, devices) {
assert(dev_inst);
const string title = dev_inst->format_device_title();
const QString title = dev_inst->format_device_title();
const void *id = dev_inst->get_id();
assert(id);
......@@ -181,7 +181,7 @@ void SamplingBar::set_device_list(
selected_index = _device_selector.count();
_device_selector_map[id] = dev_inst;
_device_selector.addItem(title.c_str(),
_device_selector.addItem(title,
qVariantFromValue((void*)id));
}
......
{
{
"Device": "DSCope",
"DeviceMode": 1,
"Horizontal trigger position": "0",
"Operation Mode": "Normal",
"Sample count": "1048576",
"Sample rate": "50000",
"Time base": "2000000000",
"Sample rate": "100000000",
"Time base": "10000",
"Trigger hold off": "0",
"Trigger slope": "0",
"Trigger source": "0",
"channel": [
{
"colour": "#eeb211",
"coupling": 1,
"coupling": 0,
"enabled": true,
"index": 0,
"name": "0",
......
{
{
"Device": "DSLogic",
"DeviceMode": 0,
"Filter Targets": "None",
......@@ -6,13 +6,53 @@
"Operation Mode": "Normal",
"Sample count": "16777216",
"Sample rate": "100000000",
"Threshold Level": "1.8/2.5/3.3V Level",
"Threshold Level": 1,
"Trigger hold off": "0",
"Trigger slope": "0",
"Trigger source": "0",
"Using Clock Negedge": 0,
"Using External Clock": 0,
"channel": [
{
"colour": "#16191a",
"enabled": true,
"index": 0,
"name": "0",
"strigger": 0,
"type": 10000
},
{
"colour": "#8f5202",
"enabled": true,
"index": 1,
"name": "1",
"strigger": 0,
"type": 10000
},
{
"colour": "#cc0000",
"enabled": true,
"index": 2,
"name": "2",
"strigger": 0,
"type": 10000
},
{
"colour": "#f57900",
"enabled": true,
"index": 3,
"name": "3",
"strigger": 0,
"type": 10000
},
{
"colour": "#edd400",
"enabled": true,
"index": 4,
"name": "4",
"strigger": 0,
"type": 10000
},
{
"colour": "#73d216",
"enabled": true,
......@@ -21,6 +61,62 @@
"strigger": 0,
"type": 10000
},
{
"colour": "#3465a4",
"enabled": true,
"index": 6,
"name": "6",
"strigger": 0,
"type": 10000
},
{
"colour": "#75507b",
"enabled": true,
"index": 7,
"name": "7",
"strigger": 0,
"type": 10000
},
{
"colour": "#16191a",
"enabled": true,
"index": 8,
"name": "8",
"strigger": 0,
"type": 10000
},
{
"colour": "#8f5202",
"enabled": true,
"index": 9,
"name": "9",
"strigger": 0,
"type": 10000
},
{
"colour": "#cc0000",
"enabled": true,
"index": 10,
"name": "10",
"strigger": 0,
"type": 10000
},
{
"colour": "#f57900",
"enabled": true,
"index": 11,
"name": "11",
"strigger": 0,
"type": 10000
},
{
"colour": "#edd400",
"enabled": true,
"index": 12,
"name": "12",
"strigger": 0,
"type": 10000
},
{
"colour": "#73d216",
"enabled": true,
......@@ -28,6 +124,22 @@
"name": "13",
"strigger": 0,
"type": 10000
},
{
"colour": "#3465a4",
"enabled": true,
"index": 14,
"name": "14",
"strigger": 0,
"type": 10000
},
{
"colour": "#75507b",
"enabled": true,
"index": 15,
"name": "15",
"strigger": 0,
"type": 10000
}
],
"trigger": {
......
......@@ -348,7 +348,7 @@ static int fpga_config(struct libusb_device_handle *hdl, const char *filename)
struct stat f_stat;
sr_info("Configure FPGA using %s", filename);
if ((fw = fopen(filename, "rb")) == NULL) {
if ((fw = g_fopen(filename, "rb")) == NULL) {
sr_err("Unable to open FPGA bit file %s for reading: %s",
filename, strerror(errno));
return SR_ERR;
......@@ -671,7 +671,7 @@ static GSList *scan(GSList *options)
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
conn = g_variant_get_string(src->data, NULL);
break;
}
}
......@@ -741,9 +741,11 @@ static GSList *scan(GSList *options)
sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]),
libusb_get_device_address(devlist[i]), NULL);
} else {
char filename[256];
sprintf(filename,"%s%s",config_path,prof->firmware);
const char *firmware = filename;
char *firmware = malloc(strlen(config_path)+strlen(prof->firmware)+1);
if (firmware == NULL)
return NULL;
strcpy(firmware, config_path);
strcat(firmware, prof->firmware);
if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION,
firmware) == SR_OK)
/* Store when this device's FW was updated. */
......@@ -987,10 +989,11 @@ static int dev_open(struct sr_dev_inst *sdi)
} else {
/* Takes >= 10ms for the FX2 to be ready for FPGA configure. */
g_usleep(10 * 1000);
char filename[256];
sprintf(filename,"%s%s",config_path,devc->profile->fpga_bit33);