static int rpmfd_init(rpmfdObject *s, PyObject *args, PyObject *kwds) { char *kwlist[] = { "obj", "mode", "flags", NULL }; const char *mode = "r"; const char *flags = "ufdio"; char *rpmio_mode = NULL; PyObject *fo = NULL; FD_t fd = NULL; int fdno; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, &fo, &mode, &flags)) return -1; rpmio_mode = rstrscat(NULL, mode, ".", flags, NULL); if (PyBytes_Check(fo)) { fd = openPath(PyBytes_AsString(fo), rpmio_mode); } else if (PyUnicode_Check(fo)) { PyObject *enc = NULL; int rc; #if PY_MAJOR_VERSION >= 3 rc = PyUnicode_FSConverter(fo, &enc); #else rc = utf8FromPyObject(fo, &enc); #endif if (rc) { fd = openPath(PyBytes_AsString(enc), rpmio_mode); Py_DECREF(enc); } } else if (rpmfdObject_Check(fo)) { rpmfdObject *fdo = (rpmfdObject *)fo; fd = openFd(fdDup(Fileno(fdo->fd)), rpmio_mode); } else if ((fdno = PyObject_AsFileDescriptor(fo)) >= 0) { fd = openFd(fdDup(fdno), rpmio_mode); } else { PyErr_SetString(PyExc_TypeError, "path or file object expected"); } if (fd != NULL) { Fclose(s->fd); /* in case __init__ was called again */ free(s->mode); free(s->flags); s->fd = fd; s->mode = rstrdup(mode); s->flags = rstrdup(flags); } else { PyErr_SetString(PyExc_IOError, Fstrerror(fd)); } free(rpmio_mode); return (fd == NULL) ? -1 : 0; }
/*! \param containerFile The path of the container file. \return Returns a ResultOfOpening value indicating the result of the operation. */ TNxSpooler::ResultOfOpening TNxSpooler::openPathWrittenInside(const QString &containerFile) { QDEBUG_METHOD_NAME; QStringList arguments; // Read the path inside the file QFile container(containerFile); container.open(QIODevice::ReadOnly); QString path = container.readLine().trimmed(); container.close(); // Try to adapt the path to the running system #ifdef Q_WS_WIN path.replace(QRegExp("^smb://"), "\\\\"); path.replace("/", QDir::separator()); #else path.replace(QRegExp("^\\\\\\\\"), "smb://"); path.replace("\\", QDir::separator()); #endif // Note: we'll check later the existence of what "path" refers to // Try to activate the NxSpooler window (set the focus to its window) so that the // new opened window has the focus. Note: the operating system has to allow that. activateWindow(); qDebug() << TDebug::indentation << "The path that must be opened is: " << path; QFileInfo aux(path); // Note: we indicate that we found the path inside a container file return openPath(aux, containerFile, true); }
void MinervaWindow::openDocument(){ QString *path; path=new QString(QFileDialog::getOpenFileName(this)); if(!path->isEmpty()){ openPath(path); } }
ZExport (ZProfile &) ZProfile::getValues (ZStringlist & aList) { ZFUNCTRACE_DEVELOP ("ZProfile::getValues(ZStringlist& aList)"); aList.drop (); #ifdef ZC_WIN openPath (zFalse); char buffer[MAX_PATH]; long bufsize; for (unsigned long key = 0;; key++) { bufsize = sizeof (buffer); if (RegEnumValue ((HKEY) iPathHandle, key, buffer, (LPDWORD) & bufsize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) break; aList.addAsLast (buffer); } // for #endif #ifdef ZC_OS2 if (!iPath.size ()) return *this; // os/2 has no values at this level openRoot (); // get size of list (not including the terminating 0) unsigned long size; if (!PrfQueryProfileSize (iRootHandle, iPath, 0, &size)) throwSysErr (PrfQueryProfileSizeName); if (size) { // create buffer ZString buf (0, size++); // read list of values if (!PrfQueryProfileData (iRootHandle, iPath, 0, buf, &size)) throwSysErr (PrfQueryProfileDataName); // parse values into stringlist char *s = buf; while (size) { ZString key; while (*s && size) { key += *s++; size--; } if (key.size ()) aList.addAsLast (key); if (size) { s++; size--; } } // while } // if #endif return *this; } // getValues
ZExport (int) ZProfile::valueType (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::valueType(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD dataType; if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, NULL, NULL) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); switch (dataType) { case 1: // String case 2: // ExpandString return String; case 3: // Binary case 7: // MultiString return Binary; case 4: // DWord case 5: // DWordBigEndian return Integer; default:; } // switch return Other; #endif #ifdef ZC_OS2 ZString val (value (aValueName)); if (ZString (val.asLong ()) == val) return Integer; if (val.isPrintable ()) return String; return Binary; #endif } // valueType
void WareSrcWidgetCollection::newSimulatorFromGhost(const openfluid::ware::SimulatorSignature& Signature) { openfluid::ui::waresdev::NewWareDialog Dialog(Signature, QApplication::activeWindow()); if (Dialog.exec()) { QString NewPath = Dialog.getNewWarePath(); if (!NewPath.isEmpty()) openPath(NewPath); } }
void WareSrcWidgetCollection::openWare(openfluid::ware::WareType Type, const QString& Title) { QString PathToOpen = openfluid::ui::waresdev::WareExplorerDialog::getOpenWarePath(QApplication::activeWindow(), mp_Manager->getWareTypePath(Type), Title); if (PathToOpen.isEmpty()) return; openPath(PathToOpen); }
void WareSrcWidgetCollection::newWare(openfluid::ware::WareType Type) { openfluid::ui::waresdev::NewWareDialog Dialog(Type, QApplication::activeWindow()); if (Dialog.exec()) { QString NewPath = Dialog.getNewWarePath(); if (!NewPath.isEmpty()) openPath(NewPath); } }
// Open the parent directory of the given path with a file manager and select // (if possible) the item at the given path void Utils::Misc::openFolderSelect(const QString &absolutePath) { const QString path = Utils::Fs::fromNativePath(absolutePath); // If the item to select doesn't exist, try to open its parent if (!QFileInfo(path).exists()) { openPath(path.left(path.lastIndexOf("/"))); return; } #ifdef Q_OS_WIN HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16())); if (pidl) { ::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0); ::ILFree(pidl); } if ((hresult == S_OK) || (hresult == S_FALSE)) ::CoUninitialize(); #elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) QProcess proc; proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory"); proc.waitForFinished(); QString output = proc.readLine().simplified(); if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path)); else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop") || (output == "nautilus-folder-handler.desktop")) proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); else if (output == "nemo.desktop") proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop")) proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path)); else // "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003 openPath(path.left(path.lastIndexOf("/"))); #else openPath(path.left(path.lastIndexOf("/"))); #endif }
ZExport (ZProfile &) ZProfile::deleteValue (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::deleteValue(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); RegDeleteValue ((HKEY) iPathHandle, aValueName); #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, 0)) throwSysErr (PrfWriteProfileStringName); #endif return *this; } // deleteValue
ZExport (long) ZProfile::longValue (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::longValue(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD data, dataType, size (4); if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, (LPBYTE) & data, &size) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); if (dataType != 4) ZTHROWEXC (UnsupportedDataType); return data; #endif #ifdef ZC_OS2 return value (aValueName).asLong (); #endif } // longValue
ZExport (ZBoolean) ZProfile::valueExists (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::valueExists(const ZString& aValueName)"); #ifdef ZC_WIN try { openPath (zFalse); } catch (const ZException & exc) { return zFalse; } // catch #endif #ifdef ZC_OS2 openRoot (); #endif ZStringlist list; getValues (list); return list.find (aValueName) >= 0; } // valueExists
ZExport (ZProfile &) ZProfile::setValue (long aValue, const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::setValue(const ZString& aValue, const ZString& aValueName, int aType)"); #ifdef ZC_WIN openPath (zTrue); if (valueExists (aValueName)) deleteValue (aValueName); if (!RegSetValueEx ((HKEY) iPathHandle, aValueName, 0, 4, (LPBYTE) & aValue, 4) == ERROR_SUCCESS) throwSysErr (SRegSetValueEx); #endif #ifdef ZC_OS2 setValue (ZString (aValue)); #endif return *this; } // setValue
void WareSrcWidgetCollection::saveAsMayBeAboveWare() { QString NewFilePath = saveAs(mp_Manager->getWorkspacePath()); // the new file is not above the current ware if (NewFilePath.isEmpty()) return; openfluid::waresdev::WareSrcManager::PathInfo NewPathInfo = openfluid::waresdev::WareSrcManager::instance() ->getPathInfo(NewFilePath); if (WareSrcWidget* Ware = m_WareSrcWidgetByPath.value(NewPathInfo.m_AbsolutePathOfWare, 0)) { // in case the new path was already opened int EditorIndex = Ware->closeFileTab(NewFilePath); Ware->openFileTab(NewPathInfo, EditorIndex); } openPath(NewFilePath); }
ZExport (ZBoolean) ZProfile::keyExists (const ZString & aKeyName) { ZFUNCTRACE_DEVELOP ("ZProfile::keyExists(const ZString& aKeyName)"); ZStringlist list; ZBoolean found; if (aKeyName.size ()) { getKeys (list); found = list.find (aKeyName) >= 0; } else { #ifdef ZC_WIN found = zTrue; try { openPath (zFalse); } catch (const ZException & exc) { found = zFalse; } // catch #endif #ifdef ZC_OS2 ZString path (iPath); try { setPath (""); getKeys (list); found = list.find (path) >= 0; setPath (path); } // try catch (const ZException & exc) { setPath (path); throw; } // catch #endif } // if return found; } // keyExists
static int seg_write( btFileSet *fs, btPartialPiece *piece) { btFile *f; _int64 addr = (_int64)piece->piecenumber * fs->blocksize; int ifile; for (ifile=0; ifile < fs->nfiles; ifile++) { int blocklen = seg_piecelen( fs, piece->piecenumber); f=fs->file[ifile]; if ( f->start+f->len >= addr && f->start < addr + blocklen) { /* this file (partly) includes this piece */ _int64 beg = f->start - addr; off_t fpos=0; _int64 len; int fd = openPath( f->path, O_CREAT | O_WRONLY); if (fd < 0) { return -1; } if (beg<0) { fpos=-beg; beg=0; } len = min(f->len - fpos, (_int64)blocklen - beg); if (lseek( fd, fpos, SEEK_SET) != fpos) { return -1; } bt_assert( len <= fs->blocksize); if (write( fd, piece->buffer+beg, len) != len) { return -1; } } } bs_set( &fs->completed, piece->piecenumber); return 0; }
ZExport (ZString) ZProfile::value (const ZString & aValueName) { ZFUNCTRACE_DEVELOP ("ZProfile::value(const ZString& aValueName)"); #ifdef ZC_WIN openPath (zFalse); DWORD dataType, size; if (!RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, &dataType, NULL, &size) == ERROR_SUCCESS) ZTHROWEXC (ValueNotFound); if (size) { ZString str (0, size); RegQueryValueEx ((HKEY) iPathHandle, aValueName, 0, NULL, (LPBYTE) (char *) str, (LPDWORD) & size); switch (dataType) { case 1: // String case 2: // ExpandString case 7: // MultiString if (str.size () > 0 && str[str.size ()] == 0) return str.subString (1, str.size ()); default:; } // switch } // if #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); // query size of data unsigned long size; if (!PrfQueryProfileSize (iRootHandle, iPath, aValueName, &size)) throwSysErr (PrfQueryProfileSizeName); if (size > 0) { ZString buf (0, size++); // try to get as string first PrfQueryProfileString (iRootHandle, iPath, aValueName, "", buf, size); ERRORID err = WinGetLastError (iHab); if (err == 0) { if (buf[buf.size ()] == 0 && buf.subString (1, buf.size () - 1).isPrintable ()) return buf.subString (1, buf.size () - 1); return buf; } // if if (ERRORIDERROR (err) != PMERR_INVALID_ASCIIZ) throwSysErr (PrfQueryProfileStringName); // try to get binary data if (!PrfQueryProfileData (iRootHandle, iPath, aValueName, buf, &size)) throwSysErr (PrfQueryProfileDataName); return buf; } // if #endif return ZString (); } // value
int main() { // Initial setup signal(SIGINT, shutDown); openPath(); instructions(); srand(time(NULL)); game_state currGame; memset(&currGame, 0, sizeof(game_state)); // Sets up piezobuzzer for sound using designated PWM pin pwm = fopen("/sys/devices/bone_capemgr.9/slots", "w"); fseek(pwm, 0, SEEK_END); fprintf(pwm, "am33xx_pwm"); fprintf(pwm, "bone_pwm_P9_14"); fflush(pwm); // Sets the pointers to the appropriate duty and period files dirDuty = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/duty", "w"); dirT = fopen("/sys/devices/ocp.3/pwm_test_P9_14.15/period", "w"); // Main game loop while (!currGame.quit) { char *playScreen = " Press button to start! "; write(fd_lcd, playScreen, SCREEN_SIZE * 3); pressAnyButton(); // usleep necessary here to prevent signal overlap once game begins usleep(500000); // Initializes the playing screen char symbolScreen[SCREEN_SIZE + 1]; int i; for (i = 0; i < SCREEN_SIZE; i++) { symbolScreen[i] = ' '; } symbolScreen[SCREEN_SIZE] = '\0'; session_state currSession; memset(&currSession, 0, sizeof(session_state)); currSession.misses = -1; // Current game session loop while (currSession.misses < WRONG_GUESSES) { // When software counter resets, update to the next screen frame if (currSession.counter == 0) { // Respond to player's input if (currSession.correctInput && symbolScreen[0] != ' ') { currSession.currScore++; } else if (!currSession.correctInput) { currSession.misses++; } currSession.inputted = 0; currSession.correctInput = 0; if (nextScreenFrame(&currSession, symbolScreen) == -1) { shutDown(); return EXIT_FAILURE; } } // Delay inbetween input update usleep(DELAY_TIME); // Reads the current status of the button inputs read(fd_but, currGame.inputs, NUM_BUTTONS * sizeof(int)); currSession.pressed = 5; for (i = 0; i < NUM_BUTTONS; i++) { if (currGame.inputs[i] == 1) { currSession.pressed = i; } } // Play sound on buzzer which corresponds to the input // This is done less often to improve smoothness of gameplay if (currSession.counter % 15 == 0) { if (currSession.pressed == 0) { buzzer(noteA); } else if (currSession.pressed == 1) { buzzer(noteB); } else if (currSession.pressed == 2) { buzzer(noteC); } else if (currSession.pressed == 3) { buzzer(noteD); } else if (currSession.pressed == 4) { buzzer(noteE); } else { buzzer(0); } } updateSession(&currSession, symbolScreen[0]); } printGameOver(currSession.currScore, &(currGame.highScore)); pressAnyButton(); usleep(500000); // Prompts user to choose to play again currGame.quit = wantToQuit(); usleep(500000); } shutDown(); return EXIT_SUCCESS; }
Joystick::Joystick() { openPath("/dev/input/js0"); }
Joystick::Joystick(int joystickNumber) { std::stringstream sstm; sstm << "/dev/input/js" << joystickNumber; openPath(sstm.str()); }
Joystick::Joystick(std::string devicePath) { openPath(devicePath); }
ZExport (ZProfile &) ZProfile::setValue (const ZString & aValue, const ZString & aValueName, int aType) { ZFUNCTRACE_DEVELOP ("ZProfile::setValue(const ZString& aValue, const ZString& aValueName, int aType)"); // find out type if auto if (aType == Auto) { ZString v (aValue); if (ZString (v.strip ().asLong ()) == v) aType = Integer; else { if (aValue.isPrintable ()) aType = String; else aType = Binary; } // if } // if #ifdef ZC_WIN long dataType; switch (aType) { case String: dataType = 1; // String break; case Integer: return setValue (aValue.asLong (), aValueName); default: dataType = 3; // Binary } // switch openPath (zTrue); if (valueExists (aValueName)) deleteValue (aValueName); if (!RegSetValueEx ((HKEY) iPathHandle, aValueName, 0, dataType, (LPBYTE) (const char *) aValue, aValue.size ()) == ERROR_SUCCESS) throwSysErr (SRegSetValueEx); #endif #ifdef ZC_OS2 if (!iPath.size ()) ZTHROWEXC (MissingPath); if (!aValueName.size ()) ZTHROWEXC (MissingValueName); openRoot (); switch (aType) { case String: if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, ZString::exp (aValue))) throwSysErr (PrfWriteProfileStringName); break; case Integer: { ZString v (aValue); if (!PrfWriteProfileString (iRootHandle, iPath, aValueName, ZString (v.strip ().asLong ()))) throwSysErr (PrfWriteProfileStringName); break; } // Integer default: { ZString val (aValue); if (!PrfWriteProfileData (iRootHandle, iPath, aValueName, (char *) val, val.size ())) throwSysErr (PrfWriteProfileDataName); } // default } // switch #endif return *this; } // setValue
FileUI::FileUI(QWidget *parent) : QWidget(parent) { mData = new PrivData(); // 开始创建界面UI // 先创建接收界面 QFrame *frame1 = new QFrame(this); frame1->setWindowIconText(cns("接收")); QVBoxLayout *v1 = new QVBoxLayout(); QLabel *l1 = new QLabel(cns("接收总进度"), frame1); QLabel *l2 = new QLabel(cns("当前文件进度"), frame1); QProgressBar *bar1 = new QProgressBar(frame1); bar1->setMaximum(100); bar1->setMinimum(0); bar1->setValue(0); connect(this, SIGNAL(signalRecvTotalProgress(int)), bar1, SLOT(setValue(int))); QProgressBar *bar2 = new QProgressBar(frame1); bar2->setMaximum(100); bar2->setMinimum(0); bar2->setValue(0); connect(this, SIGNAL(signalRecvCurrentProgress(int)), bar2, SLOT(setValue(int))); mRecvMsg = new QLabel(cns("接收消息..."), frame1); QFont f; f.setPixelSize(10); mRecvMsg->setFont(f); QPushButton *pb1 = new QPushButton(cns("停止接收"), frame1); connect(pb1, SIGNAL(clicked()), this, SLOT(stopRecv())); QPushButton *pb4 = new QPushButton(cns("打开文件夹"), frame1); connect(pb4, SIGNAL(clicked()), this, SLOT(openPath())); mRecvList = new QListWidget(frame1); QHBoxLayout *rhb1 = new QHBoxLayout(); QHBoxLayout *rhb2 = new QHBoxLayout(); rhb1->addWidget(l1, 0, Qt::AlignCenter); rhb1->addWidget(bar1, 0, Qt::AlignCenter); rhb2->addWidget(l2, 0, Qt::AlignCenter); rhb2->addWidget(bar2, 0, Qt::AlignCenter); v1->addLayout(rhb1); v1->addLayout(rhb2); v1->addWidget(mRecvMsg, 0, Qt::AlignLeft | Qt::AlignTop); v1->addWidget(mRecvList); QHBoxLayout *h2 = new QHBoxLayout(); h2->addWidget(pb1); h2->addWidget(pb4); v1->addLayout(h2); frame1->setLayout(v1); QStatusBar *status1 = new QStatusBar(frame1); mRecvLabel = new QLabel(cns("接收速度:0MB/s"), frame1); status1->addPermanentWidget(mRecvLabel); frame1->layout()->addWidget(status1); // 再创建发送界面 QFrame *frame2 = new QFrame(this); frame2->setWindowIconText(cns("发送")); QLabel *l4 = new QLabel(cns("发送总进度"), frame2); QLabel *l5 = new QLabel(cns("当前文件进度"), frame2); QProgressBar *bar3 = new QProgressBar(frame2); bar3->setMaximum(100); bar3->setMinimum(0); bar3->setValue(0); connect(this, SIGNAL(signalSendTotalProgress(int)), bar3, SLOT(setValue(int))); QProgressBar *bar4 = new QProgressBar(frame2); bar4->setMaximum(100); bar4->setMinimum(0); bar4->setValue(0); connect(this, SIGNAL(signalSendCurrentProgress(int)), bar4, SLOT(setValue(int))); mSendMsg = new QLabel(cns("发送消息..."), frame2); mSendMsg->setFont(f); QPushButton *pb2 = new QPushButton(cns("开始发送"), frame2); connect(pb2, SIGNAL(clicked()), this, SLOT(askSend())); QPushButton *pb3 = new QPushButton(cns("停止发送"), frame2); connect(pb3, SIGNAL(clicked()), this, SLOT(stopSend())); mClear = new QPushButton(cns("清空列表"), frame2); connect(mClear, SIGNAL(clicked()), this, SLOT(clearList())); mList = new QListWidget(frame2); connect(mList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*))); QVBoxLayout *v2 = new QVBoxLayout(); QHBoxLayout *shb1 = new QHBoxLayout(); QHBoxLayout *shb2 = new QHBoxLayout(); shb1->addWidget(l4, 0, Qt::AlignCenter); shb1->addWidget(bar3, 0, Qt::AlignCenter); shb2->addWidget(l5, 0, Qt::AlignCenter); shb2->addWidget(bar4, 0, Qt::AlignCenter); v2->addLayout(shb1); v2->addLayout(shb2); v2->addWidget(mSendMsg, 0, Qt::AlignLeft | Qt::AlignTop); QHBoxLayout *h1 = new QHBoxLayout(); h1->addWidget(pb2); h1->addWidget(pb3); h1->addWidget(mClear); v2->addWidget(mList); v2->addLayout(h1); frame2->setLayout(v2); QStatusBar *status2 = new QStatusBar(frame2); mSendLabel = new QLabel(cns("发送速度:0MB/s"), frame2); status2->addPermanentWidget(mSendLabel); frame2->layout()->addWidget(status2); QVBoxLayout *v3 = new QVBoxLayout(); v3->addWidget(frame1); QSpacerItem *item = new QSpacerItem(192, 10); v3->addSpacerItem(item); v3->addWidget(frame2); setLayout(v3); // resize(192, 372); // 连接信息 connect(mData->opt, SIGNAL(recvInformation(QString,QString)), this, SLOT(recvInfo(QString,QString))); connect(mData->opt, SIGNAL(sendInformation(QString,QString)), this, SLOT(sendInfo(QString,QString))); connect(mData->opt, SIGNAL(recvFilesProgress(int)), this, SIGNAL(signalRecvTotalProgress(int))); connect(mData->opt, SIGNAL(recvCurrentFileProgress(int)), this, SIGNAL(signalRecvCurrentProgress(int))); connect(mData->opt, SIGNAL(sendFilesProgress(int)), this, SIGNAL(signalSendTotalProgress(int))); connect(mData->opt, SIGNAL(sendCurrentFileProgress(int)), this, SIGNAL(signalSendCurrentProgress(int))); connect(this, SIGNAL(signalStartSend()), this, SLOT(startSend())); connect(mData->opt, SIGNAL(signalRecvPreInfo(QStringList)), this, SLOT(insertRecvFile(QStringList))); connect(mData->opt, SIGNAL(signalRecvStart()), this, SLOT(recvstart())); connect(mData->opt, SIGNAL(signalRecvSuccess()), this, SLOT(recvsuccess())); connect(mData->opt, SIGNAL(signalSendStart()), this, SLOT(sendstart())); connect(mData->opt, SIGNAL(signalSendSuccess()), this, SLOT(sendsuccess())); connect(mData->opt, SIGNAL(sendFileSpeed(float)), this, SLOT(sendSpeed(float))); connect(mData->opt, SIGNAL(recvFileSpeed(float)), this, SLOT(recvSpeed(float))); }
bool FileMgr::memToFile(const char *sFileName, const int iTableType, bool bShow){ if ( !sFileName ) { return false; } setFileName(sFileName); setTableType(iTableType); char sFullFileName[500]={0}; if ('/' != m_sFileName[0] ) { strcat(sFullFileName, m_sFilePath); strcat(sFullFileName, m_sFileName); }else { for(int j=(strlen(sFileName)-1);j>0;j--) { if(m_sFileName[j]=='/') { strncpy(m_sFilePath,m_sFileName,j); break; } } strcat(sFullFileName, m_sFileName); } if(!openPath(m_sFilePath)) { return false; } Log::log(0, "导出文件的路径是:%s", m_sFilePath); if ( !access(sFullFileName , R_OK|W_OK) ) { Log::log(0, "文件[%s]已存在,请重新指定文件名后再试!", sFullFileName); return false; } if ( !setColumnInfo(iTableType) ) { return false; } if ( !openDbFile(sFullFileName) ) { return false; } int iTotalCnt = 0; //待处理数据量 Log::log(0, "开始导出数据..."); switch (m_iTableType) { case TABLE_HCODE_INFO: { HCodeInfoStruct *pData = NULL; setDataStructSize(sizeof(HCodeInfoStruct)); iTotalCnt = SHMInfoCtl::getCount(TABLE_HCODE_INFO); SHMInfoCtl::getHeadData(&pData, 1); addData((char*)pData, iTotalCnt); if (bShow) { for (int i=0;i<iTotalCnt;++i) { SHMInfoCtl::showHCodeInfo(*(pData+i)); } } } break; case TABLE_MIN_INFO: { MinInfoStruct *pData = NULL; setDataStructSize(sizeof(MinInfoStruct)); iTotalCnt = SHMInfoCtl::getCount(TABLE_MIN_INFO); SHMInfoCtl::getMinData(&pData, 1); addData((char*)pData, iTotalCnt); if (bShow) { for (int i=0;i<iTotalCnt;++i) { SHMInfoCtl::showMinInfo(*(pData+i)); } } } break; case TABLE_LOCAL_INFO: { } break; case TABLE_IMSI_INFO: { IMSIInfoStruct *pData = NULL; setDataStructSize(sizeof(IMSIInfoStruct)); iTotalCnt = SHMInfoCtl::getCount(TABLE_IMSI_INFO); SHMInfoCtl::getImsiData(&pData, 1); addData((char*)pData, iTotalCnt); if (bShow) { for (int i=0;i<iTotalCnt;++i) { SHMInfoCtl::showImsiInfo(*(pData+i)); } } } break; default: { Log::log(0, "未知表类型:%d", iTableType); return false; } break; } closeFile(); Log::log(0, "共导出 %d 条数据!", iTotalCnt); return true; }
ZExport (ZProfile &) ZProfile::deleteKey (const ZString & aKeyName) { ZFUNCTRACE_DEVELOP ("ZProfile::deleteKey(const ZString& aKeyName)"); #ifdef ZC_WIN // delete all values and subkeys first ZString oldPath (iPath); try { setPath (iPath + (char) ZC_PATHSEPARATOR + aKeyName); openPath (zFalse); ZStringlist list; int i; // delete all values setValue (ZString ()); // just clear out default value getValues (list); for (i = 0; i < list.count (); i++) if (list[i].size ()) { deleteValue (list[i]); } // if // delete all subkeys getKeys (list); for (i = 0; i < list.count (); i++) deleteKey (list[i]); } // try catch (const ZException & exc) { setPath (oldPath); throw; } // catch setPath (oldPath); openPath (zFalse); RegDeleteKey ((HKEY) iPathHandle, aKeyName); #endif #ifdef ZC_OS2 if (iPath.size () && aKeyName.size ()) return *this; // no keys at this level openRoot (); if (!iPath.size () && !aKeyName.size ()) { // delete all applications: // will only do this if not the system- or user profile! if (iRootHandle == HINI_SYSTEMPROFILE || iRootHandle == HINI_USERPROFILE) return *this; ZStringlist apps; getKeys (apps); for (long i = 0; i < apps.count (); i++) if (!PrfWriteProfileString (iRootHandle, apps[i], 0, 0)) throwSysErr (PrfWriteProfileStringName); } else { if (!PrfWriteProfileString (iRootHandle, iPath.size ()? iPath : aKeyName, 0, 0)) throwSysErr (PrfWriteProfileStringName); } // if #endif return *this; } // deleteKey
void App::openPath(const QString &paths) { openPath(QStringList(paths)); }
bool FileMgr::fileToMem(const char *sFileName, const int iTableType,bool bShow ,bool bReplace){ if (0 == sFileName) return false; setFileName(sFileName); setTableType(iTableType); char sFullFileName[500]={0}; char sLineTmp[DATA_LEN]={0}; if ('/' != m_sFileName[0] ) { strcat(sFullFileName, m_sFilePath); strcat(sFullFileName, m_sFileName); }else { for(int j=(strlen(sFileName)-1);j>0;j--) { if(m_sFileName[j]=='/') { strncpy(m_sFilePath,m_sFileName,j); break; } } strcat(sFullFileName, m_sFileName); } if(!openPath(m_sFilePath)) { return false; } Log::log(0, "导入文件的路径是:%s", m_sFilePath); if ( access(sFullFileName , R_OK|W_OK) ) { m_poLogGroup->log(MBC_FILE_NOT_EXIST,LOG_LEVEL_ERROR,LOG_CLASS_ERROR,LOG_TYPE_PROC,-1,NULL,"指定文件不存在[%s]",sFullFileName); Log::log(0, "文件[%s]不存在,请重新指定文件名后再试!", sFullFileName); return false; } if ( !setColumnInfo(iTableType) ) { return false; } if (!openFile(sFullFileName, "r")) { return false; } //读取文件内字段名 if ( getLine(sLineTmp, DATA_LEN-1, '\n') ) { if ( !checkColumn(sLineTmp) ) return false; } else { Log::log(0, "读取文件内字段名信息出错,请检查文件!"); return false; } //处理每一行 int iTotalCnt = 0; int iUpdCnt = 0; Log::log(0, "开始导入数据..."); while ( getLine(sLineTmp, DATA_LEN-1, '\n') ) { if ( 0 == sLineTmp[0] ) { continue; } if ( !flushToMem(sLineTmp, bShow, iUpdCnt,bReplace) ) { //每行数据写入内存 Log::log(0, "无法加载数据,此行为:\n%s", sLineTmp); return false; } ++iTotalCnt; } closeFile(); Log::log(0, "共导入 %d 条数据:更新 %d 条,新增 %d 条!", iTotalCnt, iUpdCnt, iTotalCnt - iUpdCnt); return true; }
/*! Files with the special extensions will contain a path to be open. */ void TNxSpooler::detectFilesAndOpen() { // As this is a slot that can be called by Qt code (in response to a call // made by m_timer, for example), we don't allow exceptions to go out // from here, so we use a "try" block. try { QDEBUG_METHOD_NAME; // The spool folder QDir folder(m_settings.value("folder").toString()); // Note: previously we have made sure that existed: m_settings.value("folder") if (!filterAndSortFolder(folder)) return; // Exit from this function if nothing must be done if (folder.count() == 0) { qDebug() << TDebug::indentation << "Going to end: " << Q_FUNC_INFO << " AHEAD"; return; } // Stores the result of the main opening operation. This will be the value to return TNxSpooler::ResultOfOpening opResult = TNxSpooler::OpeningError; // It has this default value // To know if the file has been deleted or not bool fileHasBeenDeleted; // Information (about the file) that will appear in list of opened and deleted files by NxSpooler QString infoToAppearIntheList; QFileInfoList files = folder.entryInfoList(); // Try to open the files one by one and delete them foreach(QFileInfo file, files) { // Initialize variables fileHasBeenDeleted = false; if (file.suffix().prepend(".") == m_special_extension) { opResult = openPathWrittenInside(file.absoluteFilePath()); } else { opResult = openPath(file, folder.absolutePath()); } // See the result. The opening can fail, for example, if the user didn't specify a // valid application to open a file with that extension if (opResult == TNxSpooler::OpeningError) { syst.showWarning(tr("The file \"%1\" could not be correctly processed. Sometimes this error happens because the system " "cannot find the program specified in the configuration of NxSpooler to open files " "with that extension. The file is going to be deleted when you close this dialog window.") .arg(QDir::toNativeSeparators(file.absoluteFilePath()))); } // Try to delete the file fileHasBeenDeleted = folder.remove(file.fileName()); if (fileHasBeenDeleted == false) { // If the file couldn't be deleted, there's an external problem and // NxSpooler stops trying to open and delete all the files in its folder. QString message = tr("2805096 - The file \"%1\" could not be deleted.") .arg(QDir::toNativeSeparators(file.absoluteFilePath())); throw runtime_error(message.toStdString()); } // Prepare the information (about the file) that will appear in list of opened and deleted files by NxSpooler infoToAppearIntheList = file.fileName(); if (opResult == TNxSpooler::OpeningError) infoToAppearIntheList += tr(" (errors when opening)"); // Note: if there were problems deleting the file, NxSpooler would have stopped to avoid more problems. m_listFiles->addItem(infoToAppearIntheList); } } catch(std::exception &excep) { syst.exitBecauseException(excep); } catch(...) { syst.exitBecauseException(); } }
// Open the parent directory of the given path with a file manager and select // (if possible) the item at the given path void Utils::Misc::openFolderSelect(const QString& absolutePath) { const QString path = Utils::Fs::fromNativePath(absolutePath); #ifdef Q_OS_WIN if (QFileInfo(path).exists()) { // Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select" // Dir separators MUST be win-style slashes // QProcess::startDetached() has an obscure bug. If the path has // no spaces and a comma(and maybe other special characters) it doesn't // get wrapped in quotes. So explorer.exe can't find the correct path and // displays the default one. If we wrap the path in quotes and pass it to // QProcess::startDetached() explorer.exe still shows the default path. In // this case QProcess::startDetached() probably puts its own quotes around ours. STARTUPINFO startupInfo; ::ZeroMemory(&startupInfo, sizeof(startupInfo)); startupInfo.cb = sizeof(startupInfo); PROCESS_INFORMATION processInfo; ::ZeroMemory(&processInfo, sizeof(processInfo)); QString cmd = QString("explorer.exe /select,\"%1\"").arg(Utils::Fs::toNativePath(absolutePath)); LPWSTR lpCmd = new WCHAR[cmd.size() + 1]; cmd.toWCharArray(lpCmd); lpCmd[cmd.size()] = 0; bool ret = ::CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo); delete [] lpCmd; if (ret) { ::CloseHandle(processInfo.hProcess); ::CloseHandle(processInfo.hThread); } } else { // If the item to select doesn't exist, try to open its parent openPath(path.left(path.lastIndexOf("/"))); } #elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC) if (QFileInfo(path).exists()) { QProcess proc; QString output; proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory"); proc.waitForFinished(); output = proc.readLine().simplified(); if (output == "dolphin.desktop" || output == "org.kde.dolphin.desktop") proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path)); else if (output == "nautilus.desktop" || output == "org.gnome.Nautilus.desktop" || output == "nautilus-folder-handler.desktop") proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); else if (output == "caja-folder-handler.desktop") proc.startDetached("caja", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); else if (output == "nemo.desktop") proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path)); else if (output == "konqueror.desktop" || output == "kfmclient_dir.desktop") proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path)); else openPath(path.left(path.lastIndexOf("/"))); } else { // If the item to select doesn't exist, try to open its parent openPath(path.left(path.lastIndexOf("/"))); } #else openPath(path.left(path.lastIndexOf("/"))); #endif }
void MainWindow::openRecentFile() { if (auto action = qobject_cast<QAction*>(sender())) openPath(action->data().toString()); }