예제 #1
0
	void RollingFileAppender::rollOver()
	{
	    // Q_ASSERT_X(, "RollingFileAppender::rollOver()", "Lock must be held by caller")
	    
	    logger()->debug("Rolling over with maxBackupIndex = %1", mMaxBackupIndex);
	
	    closeFile();
	    
	    QFile f;
	    f.setFileName(file() + QLatin1Char('.') + QString::number(mMaxBackupIndex));
	    if (f.exists() && !removeFile(f))
	    	return;
	    
	    QString target_file_name;
	    int i;
	    for (i = mMaxBackupIndex - 1; i >=1; i--)
	    {
	        f.setFileName(file() + QLatin1Char('.') + QString::number(i));
	        if (f.exists())
	        {
	            target_file_name = file() + QLatin1Char('.') + QString::number(i + 1);
	            if (!renameFile(f, target_file_name))
	                return;
	        }
	    }
	
	    f.setFileName(file());
	    target_file_name = file() + QLatin1String(".1");
	    if (!renameFile(f, target_file_name))
	        return;
	    
	    openFile();
	}
예제 #2
0
/*!
 * Copy a temporary file to the real file and delete the temporary file
 * \param path is the path to the files
 * \param fileName is the real file name, which does not include the temporary prefix
 */
void ProtocolFile::copyTemporaryFile(const QString& path, const QString& fileName)
{
    bool equal = false;
    QString tempFileName = path + tempprefix + fileName;
    QString permFileName = path + fileName;

    QFile tempfile(tempFileName);
    QFile permfile(permFileName);

    // Its possible we already copied and deleted the file, so this isn't an error
    if(!tempfile.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    // Check if the files are the same
    if(permfile.open(QIODevice::ReadOnly | QIODevice::Text))
        equal = tempfile.readAll() == permfile.readAll();

    // Done with the file contents
    tempfile.close();
    permfile.close();

    if(equal)
    {
        // If the two file contents are the same, delete the temporary
        // file, leave the original file unchanged
        deleteFile(tempFileName);
    }
    else
    {
        // else if the file contents are different, delete the original
        // file and rename the temp file to be the original file
        renameFile(tempFileName, permFileName);
    }

}// ProtocolFile::copyTemporaryFile
예제 #3
0
int renameWalletScreen(char* wallet, char* newWallet) {
  // reload the wallets array after using this function!
  // newWallet will receive the new file name (complete, not friendly)
  // returns 0 if user aborts, 1 if renames.
  SetBackGround(6);
  clearLine(1,8);
  char title[MAX_WALLETNAME_SIZE+6];
  strcpy(title, wallet);
  strcat(title, " to:");
  drawScreenTitle("Rename wallet", title);
  char newname[MAX_WALLETNAME_SIZE];
  strcpy(newname, wallet);
  textInput input;
  input.forcetext=1;
  input.symbols = 0;
  input.charlimit=MAX_WALLETNAME_SIZE;
  input.buffer = (char*)newname;
  while(1) {
    input.key=0;
    int res = doTextInput(&input);
    if (res==INPUT_RETURN_EXIT) return 0; // user aborted
    else if (res==INPUT_RETURN_CONFIRM) {
      char fwallet[MAX_FILENAME_SIZE];
      walletNameToPath(newWallet, newname);
      walletNameToPath(fwallet, wallet);
      renameFile(fwallet, newWallet);
      return 1;
    }
  }
  return 0;
}
예제 #4
0
bool upgradeFilesInTemp() {
	// Get path to temp files
	string tempFilePath = "temp/";
	if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") {
		tempFilePath = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + tempFilePath;
	}
	else {
		Config &config = Config::getInstance();
		string userData = config.getString("UserData_Root","");
		if(userData != "") {
			endPathWithSlash(userData);
		}
		tempFilePath = userData + tempFilePath;
	}
	if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Temp files path [%s]\n",tempFilePath.c_str());

	// Move all files into binary folder
	bool anyFailures = false;
	vector<string> fileList = getFolderTreeContentsListRecursively(tempFilePath, "", false, NULL);
	for(unsigned int index = 0; index < fileList.size(); ++index) {
		string fileName = fileList[index];
		string newFileName = Properties::getApplicationPath() + extractFileFromDirectoryPath(fileName);
		bool result = renameFile(fileName,newFileName);
		if(result == false) {
			printf("FAILED Rename: [%s] to [%s] result = %d errno = %d\n",fileName.c_str(),newFileName.c_str(),result,errno);

			anyFailures = true;
		}
		if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",fileName.c_str(),newFileName.c_str(),result);
	}

	if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Successfully updated!\n");

	return (fileList.size() > 0 && anyFailures == false);
}
예제 #5
0
bool							XMLParser::removeChild(std::string filename, std::string value) const
{
  std::string				path;
  path = PATH;
  path += filename;
  std::ofstream				outFile("../XML_file/temp.xml");
  std::fstream				readFile(path.c_str(), std::fstream::in);
  std::string				line;

  if (outFile.fail())
    {
      print_error(" Ouverture temp.xml ");
      return (false);
    }
  if (readFile.fail())
    {
      print_error(" Lecture temp.xml ");
      return (false);
    }
  while (std::getline(readFile, line))
    {
      if (line.find("<id>" + value + "</id>") == std::string::npos)
	outFile << line << std::endl;
    }
  readFile.close();
  outFile.close();
  removeFile(path);
  renameFile("../XML_file/temp.xml", path);
  return (true);
}
예제 #6
0
/*
 * Move a file
 */
bool Directory::moveFile(string fromPath, string fromName, string toPath, string toName) {
	if (!initialised) throw std::runtime_error("Directory not Initialised");
	if (isPathNameLegal(fromPath) && isNameLegal(fromName) && isPathNameLegal(toPath) && isNameLegal(toName)) {
		// if the fromPath and toPath are the same just rename the file
		if (fromPath == toPath) {
			return renameFile(fromPath,fromName,toName);
		}
		// check the paths are valid
		int toDirectoryNode = directoryTree->getPathNode(toPath);
		int fromDirectoryNode = directoryTree->getPathNode(fromPath);
		if (fromDirectoryNode < 0) {
			cout << "path " << fromPath << " is invalid" << endl;
			return false;
		}
		if (toDirectoryNode < 0) {
			cout << "path " << toPath << " is invalid" << endl;
			return false;
		}
		// cache the from directory (path) if it is not already cached
		int fromDirectoryNodeCache = getCachedDirectory(fromDirectoryNode);
		// cache the to directory (path)
		int toDirectoryNodeCache = getCachedDirectory(toDirectoryNode);
		// check the fromName exists and is not a directory
		if (cachedDirectory[fromDirectoryNodeCache]->cache.count(fromName) < 1) {
			cout << "file " << fromName << " does not exist" << endl;
			freeCachedDirectory(fromDirectoryNodeCache);
			return false;
		} else if (iNodeList->isINodeDirectory(cachedDirectory[fromDirectoryNodeCache]->cache[fromName])) {
			cout << fromName << " refers to directory - unable to move" << endl;
			freeCachedDirectory(fromDirectoryNodeCache);
			return false;
		}
		// check the toName does not exist
		if (cachedDirectory[toDirectoryNodeCache]->cache.count(toName) > 0) {
			cout << "file/Directory " << toName << " already exists" << endl;
			freeCachedDirectory(fromDirectoryNodeCache);
			freeCachedDirectory(toDirectoryNodeCache);
			return false;
		}
		iNodeList->lockINode(toDirectoryNode);
		iNodeList->lockINode(fromDirectoryNode);
		// add the file to the to directory
		cachedDirectory[toDirectoryNodeCache]->cache[toName] = cachedDirectory[fromDirectoryNodeCache]->cache[fromName];
		// write the to directory;
		cachedDirectory[toDirectoryNodeCache]->writeCachedDirectory();
		cachedDirectory[fromDirectoryNodeCache]->cache.erase(fromName);
		// write the from directory
		cachedDirectory[fromDirectoryNodeCache]->writeCachedDirectory();
		iNodeList->unLockINode(fromDirectoryNode);
		iNodeList->unLockINode(toDirectoryNode);
		freeCachedDirectory(fromDirectoryNodeCache);
		freeCachedDirectory(toDirectoryNodeCache);
		return true;
	} else {
		cout << "Path or filename not legal" << endl;
		return false;
	}
}
예제 #7
0
int
main(int argc, char **argv) {
  time_t start,stop,stop2,now,sl;
  struct tm *t;
  int ifindex,i;
  char startstr[64],stopstr[64],stopstr2[64];
  char str[64];

  if(argc<4) {
    printf("Usage: ssb <device> <ifindex> <result path>\n");
    exit(-1);
  }

  sscanf(argv[2],"%d",&ifindex);

  //Find start time for next 5 minute time interval
  start=getNextInterval();
  stop=start+300;
  stop2=stop+300;
  
  t=localtime(&start);
  strftime(startstr,64,"%Y-%m-%d %H:%M:%S",t);
  t=localtime(&stop);
  strftime(stopstr,64,"%Y-%m-%d %H:%M:%S",t);
  t=localtime(&stop2);
  strftime(stopstr2,64,"%Y-%m-%d %H:%M:%S",t);

  createFlows(argv[1],ifindex,startstr,stopstr,argv[3]);
  for(i=0;i<=INTERVALS+1;i++)
    currentfd[i]=nextfd[i];
  createFlows(argv[1],ifindex,stopstr,stopstr2,argv[3]);

  time(&now);
  sl=start-now+310;
  while(1) {
    time(&start);
    t=localtime(&start);
    strftime(str,64,"%Y-%m-%d %H:%M:%S",t);
    sleep(sl);
    for(i=INTERVALS+1;i>=0;i--) {
      mapi_close_flow(currentfd[i]);
      currentfd[i]=nextfd[i];
    }
    renameFile(startstr,argv[3]);
    strcpy(startstr,stopstr);
    start=stop;
    stop+=300;
    stop2+=300;
    time(&now);
    sl=start-now+310;
    t=localtime(&stop);
    strftime(stopstr,64,"%Y-%m-%d %H:%M:%S",t);
    t=localtime(&stop2);
    strftime(stopstr2,64,"%Y-%m-%d %H:%M:%S",t);
    createFlows(argv[1],ifindex,stopstr,stopstr2,argv[3]);    
  }

}
예제 #8
0
void FileBrowser::createConnections()
{
    connect(renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile()));
    connect(removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
    connect(fileModel, SIGNAL(fileRenamed(QString, QString, QString)), this, SLOT(fileRenameDone()));
    auto stopEditingSlot = [&]() { fileModel->setReadOnly(true); };
    connect(fileView, &QTreeView::doubleClicked, stopEditingSlot);
    connect(openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
    connect(zipFilesAction, SIGNAL(triggered()), this, SLOT(zipFiles()));
    connect(dirView, SIGNAL(clicked(QModelIndex)), this,
            SLOT(showFiles(QModelIndex)));
}
예제 #9
0
int main()
{
    Tree * testTree;
	int (*compare)(void *, void *, void*, void*);
    void (*destroy)(void *);
    compare = &comparePointer;
    destroy = &destroyPointer;
    printDirectory("testdir/");
    deleteFile("testdir/", "text.txt");
    renameFile("testdir/b/", "6.txt", "7.txt");
    moveFile("testdir/a/aa/", "testdir/a/", "3.txt");
	return(0);
}
예제 #10
0
FormFile::FormFile(QWidget *parent) :
    QWidget(parent),fileModel(new FtpDirModel()),ftpCommandId(0),
    sourceFile(NULL),removeCommand(new QAction(tr("删除"), this)),
    renameCommand(new QAction(tr("重命名"), this)),
    ui(new Ui::FormFile)
{
    ui->setupUi(this);
    ui->lvServer->installEventFilter(this);
    ui->lvServer->setAcceptDrops(true);
    connect(removeCommand, SIGNAL(triggered()), this, SLOT(removeFile()));
    connect(renameCommand, SIGNAL(triggered()), this, SLOT(renameFile()));
    connect(&ftp, SIGNAL(commandFinished(int,bool)), this, SLOT(ftpCommandFinished(int,bool)));
    connect(&ftp, SIGNAL(dataTransferProgress(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
}
예제 #11
0
QStringList Finder::checkMissingFiles(QStringList &copiedFilesList)
{
    QStringList missingFilesList;
    uint index=0;
    if(!copiedFilesList.isEmpty()) {
        for(auto it = m_fileList.begin(); it != m_fileList.end(); ++it) {
            auto foundIt = std::find_if(copiedFilesList.begin(), copiedFilesList.end(),[&,it](QString name){ if(name.contains(*it)) return true; else return false;});
            if( foundIt == copiedFilesList.end())
                missingFilesList << renameFile(index,*it);
            index++;
        }
    }
    return missingFilesList;
}
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	_ui(new Ui::MainWindow),
	_clipboard(QApplication::clipboard()),
	_proxyModel(new QSortFilterProxyModel),
	_storageModel(),
	_objectModel(new MtpObjectsModel()),
	_uploader(new FileUploader(_objectModel, this))
{
	_ui->setupUi(this);
	setWindowIcon(QIcon(":/android-file-transfer.png"));

	_ui->listView->setModel(_proxyModel);

	_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
	_proxyModel->sort(0);
	_proxyModel->setDynamicSortFilter(true);

	_objectModel->moveToThread(QApplication::instance()->thread());

	connect(_ui->listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), SLOT(updateActionsState()));
	connect(_ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(onActivated(QModelIndex)));
	connect(_ui->listView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
	connect(_ui->actionBack, SIGNAL(triggered()), SLOT(back()));
	connect(_ui->actionGo_Down, SIGNAL(triggered()), SLOT(down()));
	connect(_ui->actionCreateDirectory, SIGNAL(triggered()), SLOT(createDirectory()));
	connect(_ui->actionUploadDirectory, SIGNAL(triggered()), SLOT(uploadDirectories()));
	connect(_ui->actionUpload_Album, SIGNAL(triggered()), SLOT(uploadAlbum()));
	connect(_ui->actionUpload, SIGNAL(triggered()), SLOT(uploadFiles()));
	connect(_ui->actionRename, SIGNAL(triggered()), SLOT(renameFile()));
	connect(_ui->actionDownload, SIGNAL(triggered()), SLOT(downloadFiles()));
	connect(_ui->actionDelete, SIGNAL(triggered()), SLOT(deleteFiles()));
	connect(_ui->storageList, SIGNAL(activated(int)), SLOT(onStorageChanged(int)));
	connect(_ui->actionRefresh, SIGNAL(triggered()), SLOT(refresh()));
	connect(_ui->actionPaste, SIGNAL(triggered()), SLOT(pasteFromClipboard()));

	connect(_objectModel, SIGNAL(onFilesDropped(QStringList)), SLOT(uploadFiles(QStringList)));
	connect(_objectModel, SIGNAL(existingFileOverwrite(QString)), SLOT(confirmOverwrite(QString)), Qt::BlockingQueuedConnection);

	connect(_clipboard, SIGNAL(dataChanged()), SLOT(validateClipboard()));
	validateClipboard();

	//fixme: find out how to specify alternative in designer
	_ui->actionBack->setShortcuts(_ui->actionBack->shortcuts() << QKeySequence("Alt+Up") << QKeySequence("Esc"));
	_ui->actionGo_Down->setShortcuts(_ui->actionGo_Down->shortcuts() << QKeySequence("Alt+Down") << QKeySequence("Enter"));
	_ui->actionCreateDirectory->setShortcuts(_ui->actionCreateDirectory->shortcuts() << QKeySequence("F7"));
	_ui->actionRefresh->setShortcuts(_ui->actionRefresh->shortcuts() << QKeySequence("Ctrl+R"));
	_ui->listView->setFocus();
}
예제 #13
0
void Renderer::waitAndSave(const int image_number) {
    const double startTime = WallClockTime();
    for (;;) {
        boost::this_thread::sleep(boost::posix_time::millisec(1000));
        const double elapsedTime = WallClockTime() - startTime;
        // Print some information about the rendering progress
        stats();
        if (elapsedTime > renderTime) {
            // Time to stop the rendering
            break;
        }
    }
    session.GetFilm().SaveOutputs();
    renameFile(image_number);
}
예제 #14
0
bool							XMLParser::addChildToParent(std::string filename, std::string parent, std::string child, std::string value) const
{
  std::string				path;
  path = PATH;
  path += filename;
  std::ofstream				outFile("../XML_file/temp.xml");
  std::fstream				readFile(path.c_str(), std::fstream::in);
  std::string				line;
  std::string				openBalise;
  std::string				childOpenBalise;
  std::string				childCloseBalise;

  if (outFile.fail())
    {
      print_error(" Ouverture temp.xml ");
      return (false);
    }
  if (readFile.fail())
    {
      print_error(" Lecture temp.xml ");
      return (false);
    }
  openBalise = "\t<" + parent + ">";
  childOpenBalise = "\n\t\t<" + child + ">";
  childCloseBalise = "</" + child + ">";
  while (std::getline(readFile, line))
    {
      size_t		pos;
      
      pos = line.find("<" + parent + ">");
      if (pos != std::string::npos)
	{
	  std::string	tmp;

	  tmp = openBalise;
	  tmp += childOpenBalise;
	  tmp += value;
	  tmp += childCloseBalise;
	  line = tmp;
	}
      outFile << line << std::endl;
    }
    readFile.close();
    outFile.close();
    removeFile(path);
    renameFile("../XML_file/temp.xml", path);
    return (true);
}
예제 #15
0
bool						XMLParser::updateNode(std::string filename, std::string node, std::string value) const
{
  std::string		path;
  path = PATH;
  path += filename;
  std::ofstream		outFile("../XML_file/temp.xml");
  std::fstream		readFile(path.c_str(), std::fstream::in);
  std::string		line;
  std::string		openBalise;
  std::string		closeBalise;

  if (outFile.fail())
    {
      print_error(" Could not open output file ");
      return (false);
    }
  if (readFile.fail())
    {
      print_error(" Could not read output file ");
      return (false);
    }
  openBalise = "\t<" + node + ">";
  closeBalise = "</" + node + ">";
  while (std::getline(readFile, line))
    {
      size_t		pos;

      pos = line.find("<" + node + ">");
      if (pos != std::string::npos)
	{
	  std::string	tmp;
	  
	  tmp = openBalise;
	  tmp += value;
	  tmp += closeBalise;
	  line = tmp;
	}
      outFile << line << std::endl;
    }
  readFile.close();
  outFile.close();
  removeFile(path);
  renameFile("../XML_file/temp.xml", path);
  return true;
}
예제 #16
0
파일: DkProcess.cpp 프로젝트: a17r/nomacs
bool DkBatchProcess::compute() {

    mIsProcessed = true;

    QFileInfo fInfoIn(mFilePathIn);
    QFileInfo fInfoOut(mFilePathOut);

    // check errors
    if (fInfoOut.exists() && mMode == DkBatchConfig::mode_skip_existing) {
        mLogStrings.append(QObject::tr("%1 already exists -> skipping (check 'overwrite' if you want to overwrite the file)").arg(mFilePathOut));
        mFailure++;
        return mFailure == 0;
    }
    else if (!fInfoIn.exists()) {
        mLogStrings.append(QObject::tr("Error: input file does not exist"));
        mLogStrings.append(QObject::tr("Input: %1").arg(mFilePathIn));
        mFailure++;
        return mFailure == 0;
    }
    else if (mFilePathIn == mFilePathOut && mProcessFunctions.empty()) {
        mLogStrings.append(QObject::tr("Skipping: nothing to do here."));
        mFailure++;
        return mFailure == 0;
    }

    // do the work
    if (mProcessFunctions.empty() && mFilePathIn == mFilePathOut && fInfoIn.suffix() == fInfoOut.suffix()) {	// rename?
        if (!renameFile())
            mFailure++;
        return mFailure == 0;
    }
    else if (mProcessFunctions.empty() && fInfoIn.suffix() == fInfoOut.suffix()) {	// copy?
        if (!copyFile())
            mFailure++;
        else
            deleteOriginalFile();

        return mFailure == 0;
    }

    process();

    return mFailure == 0;
}
예제 #17
0
void TrackOrganiser::slotButtonClicked(int button)
{
    switch (button) {
    case Ok:
        startRename();
        break;
    case Cancel:
        if (!optionsBox->isEnabled()) {
            paused=true;
            if (MessageBox::No==MessageBox::questionYesNo(this, i18n("Abort renaming of files?"), i18n("Abort"), GuiItem(i18n("Abort")), StdGuiItem::cancel())) {
                paused=false;
                QTimer::singleShot(0, this, SLOT(renameFile()));
                return;
            }
        }
        finish(false);
        // Need to call this - if not, when dialog is closed by window X control, it is not deleted!!!!
        Dialog::slotButtonClicked(button);
        break;
    default:
        break;
    }
}
예제 #18
0
void ModelView::addItem(QString fileName) {
  QListWidgetItem* item = new QListWidgetItem;
  FileInfo* fi = new FileInfo;
  fi->path->setText(fileName.replace("\\", "/"));
  fi->oldPath = fileName.replace("\\", "/");
  item->setSizeHint(fi->size());

  ui->list->addItem(item);
  ui->list->setItemWidget(item, fi);

  map[fi->remove] = item;
  map[fi->path] = item;
  connect(fi->remove, SIGNAL(clicked()), SLOT(removeFile()));
  connect(fi->path, SIGNAL(editingFinished()), SLOT(renameFile()));

  if (!QFileInfo(_scriptDir + "/" + fileName).exists()) {
    fi->path->setDisabled(true);
    fi->setToolTip(tr("File not found."));
  } else {
    ui->mainFile->addItem(fileName);
  }
  ui->modelType->setText (ui->mainFile->currentText().remove(ui->mainFile->currentText().indexOf('.'), 4));

}
예제 #19
0
bool FileSystemManager::renameFile(FileSystemActor *obj, QString newName, bool confirm)
{
	bool result = false;

	// Sanity check
	if (obj->getFileName(false) == newName) return false;

	// Check to see if the file is not VRTUAL and then commence a rename
	if (!obj->isFileSystemType(Virtual))
	{
		// remove the object from the watch list, so that it can be renamed
		if (obj->isPileized())
			removeObject(obj->getPileizedPile());

		QDir p(obj->getFullPath());
		result = renameFile(p, newName, confirm);

		// Add the pile again to reset the Listener
		if (obj->isPileized())
			addObject(obj->getPileizedPile());
	}

	return result;
}
예제 #20
0
void chanFileSystemDockWidget::createContextMenu() {

    m_actionArray[CreateFile]->setText("new file");
    connect(m_actionArray[CreateFile], SIGNAL(triggered()),
            this, SLOT(createFile()));

    m_actionArray[CreateFolder]->setText("new folder");
    connect(m_actionArray[CreateFolder], SIGNAL(triggered()),
            this, SLOT(createFolder()));

    m_actionArray[ImportFile]->setText("import file");
    connect(m_actionArray[ImportFile], SIGNAL(triggered()),
            this, SLOT(importFile()));

    m_actionArray[RemoveFile]->setText("remove file");
    connect(m_actionArray[RemoveFile], SIGNAL(triggered()),
            this, SLOT(removeFile()));

    m_actionArray[RemoveFolder]->setText("remove folder");
    connect(m_actionArray[RemoveFolder], SIGNAL(triggered()),
            this, SLOT(removeFolder()));

    m_actionArray[RenameFile]->setText("rename file");
    connect(m_actionArray[RenameFile], SIGNAL(triggered()),
            this, SLOT(renameFile()));

    m_actionArray[RenameFolder]->setText("rename folder");
    connect(m_actionArray[RenameFolder], SIGNAL(triggered()),
            this, SLOT(renameFolder()));

    std::for_each(m_actionArray, m_actionArray + actionArraySize, [this](QAction* item) {
        this->addAction(item);
    });

    setContextMenuPolicy(Qt::ContextMenuPolicy::ActionsContextMenu);
}
예제 #21
0
파일: input.c 프로젝트: A2Command/a2command
void  readKeyboard(void)
{
	struct dir_node *currentNode;
	unsigned char key;
	bool decision = false;

	key = toupper(cgetc());

	switch((int)key)
	{
	case HK_FORMATTER:
		if(loadOverlay(7))
		{
			formatDisk(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;
	case HK_BASIC_VIEWER:
		if(loadOverlay(6))
		{
			viewFileAsBASIC(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;
	case HK_HEX_EDIT:
		if(loadOverlay(5))
		{
			hexEditCurrentFile(selectedPanel);

			clrscr();
			writeMenuBar();
			reloadPanels();
		}
		break;

	case CH_ENTER:
		currentNode = getSelectedNode(selectedPanel);
		if(isDirectory(selectedPanel))
		{
			enterDirectory(selectedPanel);
		}
		else if(currentNode != NULL)
		{
			sprintf(filePath, "%s/%s", selectedPanel->path, currentNode->name);
			if(currentNode->type == 0x06
				|| currentNode->type == 0xFF)
			{
				saveScreen();
				decision = writeYesNo("Confirm", quit_message, 1);
				retrieveScreen();

				if(decision == true)
				{
					exec(filePath, NULL);
				}
			}
			else if(currentNode->type == 0xFC)
			{
				if(loadOverlay(6))
				{
					viewFileAsBASIC(selectedPanel);

					clrscr();
					writeMenuBar();
					reloadPanels();
				}
			}
			else
			{
				if(loadOverlay(1))
					viewFile(filePath);
			}
		}
		break;
	case KEY_F4:
		rereadSelectedPanel();
		break;
	case KEY_F3:
		selectDrive(selectedPanel);
		rereadSelectedPanel();
		break;
	case HK_SELECT:
		selectCurrentFile();
		break;
#ifdef __APPLE2ENH__
		case CH_CURS_UP:
#else
		case CH_CURS_LEFT:
#endif
		moveSelectorUp(selectedPanel);
		break;
#ifdef __APPLE2ENH__
		case CH_CURS_DOWN:
#else
		case CH_CURS_RIGHT:
#endif
		moveSelectorDown(selectedPanel);
		break;
#ifdef __APPLE2ENH__
	case CH_CURS_LEFT:
		if(selectedPanel == &rightPanelDrive
			&& strlen(leftPanelDrive.path) > 0)
		{
			selectedPanel = &leftPanelDrive;
			writeSelectorPosition(&leftPanelDrive, '>');
			writeSelectorPosition(&rightPanelDrive, ' ');
			writeCurrentFilename(selectedPanel);
		}
		break;
	case CH_CURS_RIGHT:
		if(selectedPanel == &leftPanelDrive
			&& strlen(rightPanelDrive.path) > 0)
		{
			selectedPanel = &rightPanelDrive;
			writeSelectorPosition(&leftPanelDrive, ' ');
			writeSelectorPosition(&rightPanelDrive, '>');
			writeCurrentFilename(selectedPanel);
		}
		break;
#endif
	case HK_SWITCH_PANEL:
		if(selectedPanel == &leftPanelDrive
			&& strlen(rightPanelDrive.path) > 0)
		{
			selectedPanel = &rightPanelDrive;
			writeSelectorPosition(&leftPanelDrive, ' ');
			writeSelectorPosition(&rightPanelDrive, '>');
			writeCurrentFilename(selectedPanel);
		}
		else if(selectedPanel == &rightPanelDrive
			&& strlen(leftPanelDrive.path) > 0)
		{
			selectedPanel = &leftPanelDrive;
			writeSelectorPosition(&leftPanelDrive, '>');
			writeSelectorPosition(&rightPanelDrive, ' ');
			writeCurrentFilename(selectedPanel);
		}
		break;

	case KEY_SH_PLUS:
		enterDirectory(selectedPanel);
		break;
	case KEY_SH_MINUS:
	case CH_ESC:
		leaveDirectory(selectedPanel);
		break;
	//case 188: // C= C - Command Menu
	//	writeMenu(command);
	//	break;
	//case 182: // C= L - Left Menu
	//	writeMenu(left);
	//	break;
	//case 178: // C= R - Right Menu
	//	writeMenu(right);
	//	break;
	//case 187: // C= F - File Menu
	//	writeMenu(file);
	//	break;
	//case 185: // C= O - Options Menu
	//	writeMenu(options);
	//	break;
	case HK_REREAD_LEFT:
		rereadDrivePanel(left);
		break;
	case HK_REREAD_RIGHT:
		rereadDrivePanel(right);
		break;
	case HK_DRIVE_LEFT:
		writeDriveSelectionPanel(left);
		break;
	case HK_DRIVE_RIGHT:
		writeDriveSelectionPanel(right);
		break;
	case HK_SELECT_ALL:
		selectAllFiles(selectedPanel, true);
		break;
	case HK_DESELECT_ALL:
		selectAllFiles(selectedPanel, false);
		break;
	case KEY_F1:
		if(loadOverlay(1))
			writeHelpPanel();
		break;
	case KEY_F2:
		quit();
		break;
	case KEY_F5:
		if(loadOverlay(4))
			copyFiles();
		break;
	case HK_RENAME:
	case KEY_F6:
		if(loadOverlay(4))
			renameFile();
		break;
	case HK_DELETE:
	case KEY_F8:
		if(loadOverlay(4))
			deleteFiles();
		break;
	//case KEY_AT:
	//	inputCommand();
	//	break;
	case KEY_F7:
		if(loadOverlay(4))
			makeDirectory();
		break;
	case HK_TO_TOP:
		moveTop(selectedPanel);
		break;
	case HK_TO_BOTTOM:
		moveBottom(selectedPanel);
		break;
	case HK_PAGE_UP:
		movePageUp(selectedPanel);
		break;
	case HK_PAGE_DOWN:
		movePageDown(selectedPanel);
		break;
	case HK_WRITE_DISK_IMAGE:
		if(loadOverlay(3))
			writeDiskImage();
		break;
	case HK_CREATE_DISK_IMAGE:
		if(loadOverlay(3))
			createDiskImage();
		break;
	case HK_COPY_DISK:
		if(loadOverlay(2))
			copyDisk();
		break;
	default:
		//writeStatusBarf("%c", key);
		break;
	}
}
예제 #22
0
void Finder::findFiles()
{
    if(!QDir(m_targetFolder).mkdir("Pliki_PDF")) {
        emit finished(false, "Folder \"Pliki_PDF\" już istnieje.");
        return;
    }

    bool isFileListLoaded = loadFileList();
    if(!isFileListLoaded)
        return;

    if(isFileListLoaded && m_fileList.size() == 0) {
        removeCopiedFiles();
        emit finished(false, "Nie znaleziono pasujących pozycji w harmonogramie.");
        return;
    }

    emit signalProgress( 100, "Określenie liczby plików do przeszukania ...");
    QDir dir(m_searchedFolder, QString("*.pdf"), QDir::NoSort, QDir::Files | QDir::NoSymLinks);
    QDirIterator counterIt(dir, QDirIterator::Subdirectories);
    filesCounter = 0;
    while (counterIt.hasNext()) {
            bool abort = m_abort;
            if (abort) {
                removeCopiedFiles();
                emit finished(false);
                return;
            }
            filesCounter++;
            counterIt.next();
    }
    if(filesCounter == 0) {
        emit finished(false, "Nie znaleziono plików PDF w wybranej lokalizacji.");
        return;
    }

    QStringList indexList;
    QStringList copiedFilesList;
    QString renamedFile;
    int count = 0;
    QDirIterator finalIt(dir, QDirIterator::Subdirectories);
    while (finalIt.hasNext()) {

        bool abort = m_abort;
        if (abort) {
            removeCopiedFiles();
            emit finished(false);
            return;
        }

        if(m_fileList.contains(QFileInfo(finalIt.filePath()).fileName(), Qt::CaseInsensitive)) {

            indexList = getFileListIdx(QFileInfo(finalIt.filePath()).fileName());

            for(int i = 0; i < indexList.size(); ++i) {

                renamedFile = renameFile(indexList.at(i).toInt(), QFileInfo(finalIt.filePath()).fileName());

                if(!QFile(m_targetFolder + "/Pliki_PDF/" + renamedFile).exists()) {
                    QFile::copy(QFileInfo(finalIt.filePath()).filePath(), m_targetFolder + "/Pliki_PDF/" + renamedFile);
                    copiedFilesList.append(renamedFile);
                    emit itemFound(renamedFile, true);
                }
            }
        }

        finalIt.next();
        count++;
        emit signalProgress( int((double(count)/double(filesCounter)*100)),
                         "Przeszukiwanie plików: " + QString::number(count) + "/" +
                         QString::number(filesCounter));
    }

    QStringList missedFiless = checkMissingFiles(copiedFilesList);

    QString information = generateCSV(missedFiless,copiedFilesList);
    emit finished(true,information);
}
예제 #23
0
int do_command(char* line, int msgLen, int num) {
	char send_buf[BUFFER_SIZE] = "";
	char recv_buf[BUFFER_SIZE] = "";
	if (lock_id == num) {
		if (clients[num].send == 1) {
			if (clients[num].totalSize > 0) {
				clients[num].totalSize -= msgLen;
				fWriteStrSize(clients[num].myFD, line, msgLen);
				do_send("OK", clients[num].fd);
			} else {
//				do_send("give me Password", clients[num].fd);
//				do_recieve(recv_buf, clients[num].fd);
				println("Password: %s", line);
				do_send("Complete", clients[num].fd);
				char fileName[BUFFER_SIZE];
				strcpy(fileName, clients[num].currentFileName);
				if (addThisFile(fileName, line, num) != 0) {
					println("There is no space for '%s'", fileName);
					do_send("Prob: no space", clients[num].fd);
					return 2;
				}
				println("Receiving file \"%s\" was completed", fileName);
				lock_id = -1;
				close(clients[num].myFD);
			}
		} else {
			if (fEndOfFile(clients[num].myFD) == 0) {
				int len = fReadSome(clients[num].myFD, send_buf,
				BUFFER_SIZE - 5);
				do_send_size(send_buf, len, clients[num].fd);
			} else {
				println("I sent all the file");
				do_send("Complete", clients[num].fd);
				lock_id = -1;
				int dif = (time(NULL ) - clients[num].startTime);
				if (dif == 0)
					dif = 1;
				println("Average transmit speed: %d (KB/Sec)",
						(clients[num].info.st_size / dif) / 1000);
				close(clients[num].myFD);
			}
		}
		return 1;
	}
	int index = 0;
	char next[BUFFER_SIZE];
	memset(next, 0, BUFFER_SIZE);
	index = nextToken(line, next, index);
	int k = -1;
	println("next token is '%s'", next);
	if (strcmp(next, "quit") == 0)
		k = -1; // quit
	else if (strcmp(next, "get-clients-list") == 0) {
		sendClientsList(num);
		k = 0; // send "get-clients-list"
	} else if (strcmp(next, "share") == 0) {
		getFile(index, num, line);
	} else if (strcmp(next, "get-files-list") == 0) {
		sendFileList(num);
		k = 3; // share
	} else if (strcmp(next, "get") == 0) {
		k = sendFile(index, num, line);
//		k =  4; // share
	} else if (strcmp(next, "remove") == 0) {
		removeFile(index, next, num, clients, line);
		k = 5; // remove
	} else if (strcmp(next, "rename") == 0) {
		renameFile(index, next, num, recv_buf, clients, line);
		k = 6; // rename
	} else if (strcmp(next, "msg") == 0) {
		strcpy(line, line + 8);
		char tmpInt[BUFFER_SIZE] = "";
		index = nextToken(line, tmpInt, 0);
		strcpy(line, line + index);
		int targetNum = atoi(tmpInt);
		if (lock_id != targetNum && targetNum < clientCount
				&& clients[targetNum].fd != -1) {
			sendMessage(num, clients, targetNum, recv_buf, line);
		} else
			do_send("Your target may be busy. Try again later!",clients[num].fd);
		k = 7; // msg
	} else if (strcmp(next, "dc") == 0) {
		int q = 0;
		k = 8; // share
	}
	return k;
}
예제 #24
0
FileSystemWidget::FileSystemWidget(LiteApi::IApplication *app, QWidget *parent) :
    QWidget(parent),
    m_liteApp(app)
{
    m_tree = new SymbolTreeView;
    m_tree->setHeaderHidden(true);

#if QT_VERSION >= 0x050000
    m_tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
    m_tree->header()->setResizeMode(QHeaderView::ResizeToContents);
#endif
    m_tree->header()->setStretchLastSection(false);

    m_model = new FileSystemModel(this);

    QDir::Filters filters = QDir::AllDirs | QDir::Files | QDir::Drives
                            | QDir::Readable| QDir::Writable
                            | QDir::Executable/* | QDir::Hidden*/
                            | QDir::NoDotAndDotDot;
#ifdef Q_OS_WIN // Symlinked directories can cause file watcher warnings on Win32.
    filters |= QDir::NoSymLinks;
#endif
    m_model->setFilter(filters);

    m_tree->setContextMenuPolicy(Qt::CustomContextMenu);
    m_tree->setModel(m_model);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    layout->addWidget(m_tree);
    this->setLayout(layout);

    connect(m_tree,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openPathIndex(QModelIndex)));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));

    m_fileMenu = new QMenu(this);
    m_folderMenu = new QMenu(this);
    m_rootMenu = new QMenu(this);

    m_openEditorAct = new QAction(tr("Open File"),this);
    m_newFileAct = new QAction(tr("New File..."),this);
    m_newFileWizardAct = new QAction(tr("New File Wizard..."),this);
    m_renameFileAct = new QAction(tr("Rename File..."),this);
    m_removeFileAct = new QAction(tr("Delete File"),this);

    m_newFolderAct = new QAction(tr("New Folder..."),this);
    m_renameFolderAct = new QAction(tr("Rename Folder..."),this);
    m_removeFolderAct = new QAction(tr("Delete Folder"),this);

    m_openShellAct = new QAction(tr("Open Terminal Here"),this);
    m_openExplorerAct = new QAction(tr("Open Explorer Here"),this);

    m_viewGodocAct = new QAction(tr("View Godoc Here"),this);

    m_addFolderAct = new QAction(tr("Add Folder..."),this);
    m_closeFolerAct = new QAction(tr("Close Folder"),this);

    m_closeAllFoldersAct = new QAction(tr("Close All Folders"),this);

    m_fileMenu->addAction(m_openEditorAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_newFileAct);
    m_fileMenu->addAction(m_newFileWizardAct);
    m_fileMenu->addAction(m_renameFileAct);
    m_fileMenu->addAction(m_removeFileAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_viewGodocAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_openShellAct);
    m_fileMenu->addAction(m_openExplorerAct);

    m_folderMenu->addAction(m_newFileAct);
    m_folderMenu->addAction(m_newFileWizardAct);
    m_folderMenu->addAction(m_newFolderAct);
    m_folderMenu->addAction(m_renameFolderAct);
    m_folderMenu->addAction(m_removeFolderAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_closeFolerAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_viewGodocAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_openShellAct);
    m_folderMenu->addAction(m_openExplorerAct);

    m_rootMenu->addAction(m_addFolderAct);
    m_rootMenu->addSeparator();
    //m_rootMenu->addAction(m_closeAllFoldersAct);

    connect(m_model->fileWatcher(),SIGNAL(directoryChanged(QString)),this,SLOT(directoryChanged(QString)));
    connect(m_openEditorAct,SIGNAL(triggered()),this,SLOT(openEditor()));
    connect(m_newFileAct,SIGNAL(triggered()),this,SLOT(newFile()));
    connect(m_newFileWizardAct,SIGNAL(triggered()),this,SLOT(newFileWizard()));
    connect(m_renameFileAct,SIGNAL(triggered()),this,SLOT(renameFile()));
    connect(m_removeFileAct,SIGNAL(triggered()),this,SLOT(removeFile()));
    connect(m_newFolderAct,SIGNAL(triggered()),this,SLOT(newFolder()));
    connect(m_renameFolderAct,SIGNAL(triggered()),this,SLOT(renameFolder()));
    connect(m_removeFolderAct,SIGNAL(triggered()),this,SLOT(removeFolder()));
    connect(m_openShellAct,SIGNAL(triggered()),this,SLOT(openShell()));
    connect(m_openExplorerAct,SIGNAL(triggered()),this,SLOT(openExplorer()));
    connect(m_viewGodocAct,SIGNAL(triggered()),this,SLOT(viewGodoc()));
    connect(m_addFolderAct,SIGNAL(triggered()),this,SLOT(addFolder()));
    connect(m_closeFolerAct,SIGNAL(triggered()),this,SLOT(closeFolder()));
    connect(m_closeAllFoldersAct,SIGNAL(triggered()),this,SLOT(closeAllFolders()));

    connect(m_tree,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(treeViewContextMenuRequested(QPoint)));
}
예제 #25
0
GopathBrowser::GopathBrowser(LiteApi::IApplication *app, QObject *parent) :
    QObject(parent),
    m_liteApp(app)
{
    m_widget = new QWidget;

    m_toolBar = new QToolBar;
    m_toolBar->setIconSize(QSize(16,16));

    m_syncEditor = new QAction(QIcon(":/images/synceditor.png"),tr("Sync Editor"),this);
    m_syncEditor->setCheckable(true);
    m_syncProject = new QAction(QIcon(":/images/syncproject.png"),tr("Sync Project"),this);
    m_syncProject->setCheckable(true);

    m_startPathLabel = new QLabel;

    m_toolBar->addAction(m_syncEditor);
    m_toolBar->addAction(m_syncProject);
    m_toolBar->addSeparator();
    m_toolBar->addWidget(m_startPathLabel);

    m_pathTree = new QTreeView;
    m_pathTree->setHeaderHidden(true);
    m_model = new GopathModel(this);
    m_pathTree->setContextMenuPolicy(Qt::CustomContextMenu);
    m_pathTree->setModel(m_model);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    layout->addWidget(m_toolBar);
    layout->addWidget(m_pathTree);
    m_widget->setLayout(layout);

    m_pathList = m_liteApp->settings()->value("golangtool/gopath").toStringList();

    //connect(m_pathTree->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(pathIndexChanged(QModelIndex)));
    connect(m_pathTree,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openPathIndex(QModelIndex)));
    LiteApi::IEnvManager* envManager = LiteApi::findExtensionObject<LiteApi::IEnvManager*>(m_liteApp,"LiteApi.IEnvManager");
    connect(envManager,SIGNAL(currentEnvChanged(LiteApi::IEnv*)),this,SLOT(reloadEnv()));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));

    m_fileMenu = new QMenu(m_widget);
    m_folderMenu = new QMenu(m_widget);

    m_setStartAct = new QAction(tr("Set Activate Project"),this);
    m_openEditorAct = new QAction(tr("Open Editor"),this);
    m_newFileAct = new QAction(tr("New File"),this);
    m_newFileWizardAct = new QAction(tr("New File Wizard"),this);
    m_renameFileAct = new QAction(tr("Rename File"),this);
    m_removeFileAct = new QAction(tr("Remove File"),this);

    m_newFolderAct = new QAction(tr("New Folder"),this);
    m_renameFolderAct = new QAction(tr("Rename Folder"),this);
    m_removeFolderAct = new QAction(tr("Remove Folder"),this);

    m_openShellAct = new QAction(tr("Open Terminal Here"),this);
    m_openExplorerAct = new QAction(tr("Open Explorer Here"),this);

    m_fileMenu->addAction(m_openEditorAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_newFileAct);
    m_fileMenu->addAction(m_newFileWizardAct);
    m_fileMenu->addAction(m_renameFileAct);
    m_fileMenu->addAction(m_removeFileAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_openShellAct);
    m_fileMenu->addAction(m_openExplorerAct);

    m_folderMenu->addAction(m_setStartAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_newFileAct);
    m_folderMenu->addAction(m_newFileWizardAct);
    m_folderMenu->addAction(m_newFolderAct);
    m_folderMenu->addAction(m_renameFolderAct);
    m_folderMenu->addAction(m_removeFolderAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_openShellAct);
    m_folderMenu->addAction(m_openExplorerAct);

    connect(m_startPathLabel,SIGNAL(linkActivated(QString)),this,SLOT(expandStartPath(QString)));
    connect(m_syncEditor,SIGNAL(triggered(bool)),this,SLOT(syncEditor(bool)));
    connect(m_syncProject,SIGNAL(triggered(bool)),this,SLOT(syncProject(bool)));
    connect(m_setStartAct,SIGNAL(triggered()),this,SLOT(setActivate()));
    connect(m_openEditorAct,SIGNAL(triggered()),this,SLOT(openEditor()));
    connect(m_newFileAct,SIGNAL(triggered()),this,SLOT(newFile()));
    connect(m_newFileWizardAct,SIGNAL(triggered()),this,SLOT(newFileWizard()));
    connect(m_renameFileAct,SIGNAL(triggered()),this,SLOT(renameFile()));
    connect(m_removeFileAct,SIGNAL(triggered()),this,SLOT(removeFile()));
    connect(m_newFolderAct,SIGNAL(triggered()),this,SLOT(newFolder()));
    connect(m_renameFolderAct,SIGNAL(triggered()),this,SLOT(renameFolder()));
    connect(m_removeFolderAct,SIGNAL(triggered()),this,SLOT(removeFolder()));
    connect(m_openShellAct,SIGNAL(triggered()),this,SLOT(openShell()));
    connect(m_openExplorerAct,SIGNAL(triggered()),this,SLOT(openExplorer()));

    connect(m_pathTree,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(treeViewContextMenuRequested(QPoint)));

    bool b = m_liteApp->settings()->value("GolangTool/synceditor",true).toBool();
    if (b) {
        m_syncEditor->toggle();
    }
    b = m_liteApp->settings()->value("GolangTool/syncproject",false).toBool();
    if (b) {
        m_syncProject->toggle();
    }
    m_startPathLabel->setText("null project");
}
예제 #26
0
FileSystemWidget::FileSystemWidget(LiteApi::IApplication *app, QWidget *parent) :
    QWidget(parent),
    m_liteApp(app)
{
    m_tree = new SymbolTreeView;
    m_tree->setHeaderHidden(true);
    m_model = new FileSystemModel(this);
    m_tree->setContextMenuPolicy(Qt::CustomContextMenu);
    m_tree->setModel(m_model);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setMargin(0);
    layout->addWidget(m_tree);
    this->setLayout(layout);

    connect(m_tree,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openPathIndex(QModelIndex)));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));

    m_fileMenu = new QMenu(this);
    m_folderMenu = new QMenu(this);

    m_openEditorAct = new QAction(tr("Open Editor"),this);
    m_newFileAct = new QAction(tr("New File"),this);
    m_newFileWizardAct = new QAction(tr("New File Wizard"),this);
    m_renameFileAct = new QAction(tr("Rename File"),this);
    m_removeFileAct = new QAction(tr("Remove File"),this);

    m_newFolderAct = new QAction(tr("New Folder"),this);
    m_renameFolderAct = new QAction(tr("Rename Folder"),this);
    m_removeFolderAct = new QAction(tr("Remove Folder"),this);

    m_openShellAct = new QAction(tr("Open Terminal Here"),this);
    m_openExplorerAct = new QAction(tr("Open Explorer Here"),this);

    m_fileMenu->addAction(m_openEditorAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_newFileAct);
    m_fileMenu->addAction(m_newFileWizardAct);
    m_fileMenu->addAction(m_renameFileAct);
    m_fileMenu->addAction(m_removeFileAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_openShellAct);
    m_fileMenu->addAction(m_openExplorerAct);

    m_folderMenu->addAction(m_newFileAct);
    m_folderMenu->addAction(m_newFileWizardAct);
    m_folderMenu->addAction(m_newFolderAct);
    m_folderMenu->addAction(m_renameFolderAct);
    m_folderMenu->addAction(m_removeFolderAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_openShellAct);
    m_folderMenu->addAction(m_openExplorerAct);


    connect(m_model->fileWatcher(),SIGNAL(directoryChanged(QString)),this,SLOT(directoryChanged(QString)));
    connect(m_openEditorAct,SIGNAL(triggered()),this,SLOT(openEditor()));
    connect(m_newFileAct,SIGNAL(triggered()),this,SLOT(newFile()));
    connect(m_newFileWizardAct,SIGNAL(triggered()),this,SLOT(newFileWizard()));
    connect(m_renameFileAct,SIGNAL(triggered()),this,SLOT(renameFile()));
    connect(m_removeFileAct,SIGNAL(triggered()),this,SLOT(removeFile()));
    connect(m_newFolderAct,SIGNAL(triggered()),this,SLOT(newFolder()));
    connect(m_renameFolderAct,SIGNAL(triggered()),this,SLOT(renameFolder()));
    connect(m_removeFolderAct,SIGNAL(triggered()),this,SLOT(removeFolder()));
    connect(m_openShellAct,SIGNAL(triggered()),this,SLOT(openShell()));
    connect(m_openExplorerAct,SIGNAL(triggered()),this,SLOT(openExplorer()));

    connect(m_tree,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(treeViewContextMenuRequested(QPoint)));
}
예제 #27
0
	bool renameFile(const char * pcSrc, const char * pcDst)
	{
		QString szPath = QString::fromUtf8(pcSrc);
		QString szPath2 = QString::fromUtf8(pcDst);
		return renameFile(szPath,szPath2);
	}
예제 #28
0
int UsbKey::renameCombo(const struct BankFile* bank, const char* newName) {
	preenFMComboInitialized = false;
	return renameFile(bank, newName);
}
예제 #29
0
FileBrowser::FileBrowser(LiteApi::IApplication *app, QObject *parent) :
    QObject(parent),
    m_liteApp(app)
{
    m_widget = new QWidget;
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);

    m_fileModel = new QFileSystemModel(this);
    m_fileModel->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);

    m_proxyModel = new QSortFileSystemProxyModel(this);
    m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    m_proxyModel->setDynamicSortFilter(true);
    m_proxyModel->setSourceModel(m_fileModel);
    m_proxyModel->sort(0);

    //create filter toolbar
    m_filterToolBar = new QToolBar(m_widget);
    m_filterToolBar->setIconSize(QSize(16,16));

    m_syncAct = new QAction(QIcon("icon:filebrowser/images/sync.png"),tr("Synchronize with editor"),this);
    m_syncAct->setCheckable(true);

    m_filterCombo = new QComboBox;
    m_filterCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_filterCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_filterCombo->setEditable(true);
    m_filterCombo->addItem("*");
    m_filterCombo->addItem("Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.e64;*.pro");
    m_filterCombo->addItem("*.sh;Makefile;*.go;*.cgo;*.s;*.goc;*.y;*.*.c;*.cpp;*.h;*.hpp;*.e64;*.pro");

    m_filterToolBar->addAction(m_syncAct);
    m_filterToolBar->addSeparator();
    m_filterToolBar->addWidget(m_filterCombo);

    //create root toolbar
    m_rootToolBar = new QToolBar(m_widget);
    m_rootToolBar->setIconSize(QSize(16,16));

    m_cdupAct = new QAction(QIcon("icon:filebrowser/images/cdup.png"),tr("Open Parent"),this);

    m_rootCombo = new QComboBox;
    m_rootCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    m_rootCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
    m_rootCombo->setEditable(false);
    m_rootCombo->addItem(m_fileModel->myComputer().toString());

    m_rootToolBar->addAction(m_cdupAct);
    m_rootToolBar->addSeparator();
    m_rootToolBar->addWidget(m_rootCombo);

    //create treeview
    m_treeView = new QTreeView;
    m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
    m_treeView->setModel(m_proxyModel);

    m_treeView->setRootIsDecorated(true);
    m_treeView->setUniformRowHeights(true);
    m_treeView->setTextElideMode(Qt::ElideNone);
    m_treeView->setAttribute(Qt::WA_MacShowFocusRect, false);

    m_treeView->setHeaderHidden(true);
    m_treeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // show horizontal scrollbar
#if QT_VERSION >= 0x050000
    m_treeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
#else
    m_treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
#endif
    m_treeView->header()->setStretchLastSection(false);
    //hide
    int count = m_treeView->header()->count();
    for (int i = 1; i < count; i++) {
        m_treeView->setColumnHidden(i,true);
    }

    mainLayout->addWidget(m_filterToolBar);
    mainLayout->addWidget(m_rootToolBar);
    mainLayout->addWidget(m_treeView);
    m_widget->setLayout(mainLayout);

    //create menu
    m_fileMenu = new QMenu;
    m_folderMenu = new QMenu;
    m_rootMenu = new QMenu;

    m_openFileAct = new QAction(tr("Open File"),this);
    //m_openEditorAct = new QAction(tr("Open Editor"),this);
    m_newFileAct = new QAction(tr("New File..."),this);
    m_newFileWizardAct = new QAction(tr("New File Wizard..."),this);
    m_renameFileAct = new QAction(tr("Rename File..."),this);
    m_removeFileAct = new QAction(tr("Delete File"),this);

    m_setRootAct = new QAction(tr("Set As Root Folder"),this);
    m_newFolderAct = new QAction(tr("New Folder..."),this);
    m_renameFolderAct = new QAction(tr("Rename Folder..."),this);
    m_removeFolderAct = new QAction(tr("Delete Folder"),this);

    m_openShellAct = new QAction(tr("Open Terminal Here"),this);
    m_openExplorerAct = new QAction(tr("Open Explorer Here"),this);

    m_viewGodocAct = new QAction(tr("View Godoc Here"),this);

    m_loadFolderAct = new QAction(tr("Load Folder Project"),this);

    m_fileMenu->addAction(m_openFileAct);
    //m_fileMenu->addAction(m_openEditorAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_newFileAct);
    m_fileMenu->addAction(m_newFileWizardAct);
    m_fileMenu->addAction(m_renameFileAct);
    m_fileMenu->addAction(m_removeFileAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_loadFolderAct);
    m_fileMenu->addAction(m_viewGodocAct);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_openShellAct);
    m_fileMenu->addAction(m_openExplorerAct);

    m_folderMenu->addAction(m_setRootAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_newFileAct);
    m_folderMenu->addAction(m_newFileWizardAct);
    m_folderMenu->addAction(m_newFolderAct);
    m_folderMenu->addAction(m_renameFolderAct);
    m_folderMenu->addAction(m_removeFolderAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_loadFolderAct);
    m_folderMenu->addAction(m_viewGodocAct);
    m_folderMenu->addSeparator();
    m_folderMenu->addAction(m_openShellAct);
    m_folderMenu->addAction(m_openExplorerAct);

    m_rootMenu->addAction(m_cdupAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_newFileAct);
    m_rootMenu->addAction(m_newFileWizardAct);
    m_rootMenu->addAction(m_newFolderAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_loadFolderAct);
    m_rootMenu->addSeparator();
    m_rootMenu->addAction(m_openShellAct);
    m_rootMenu->addAction(m_openExplorerAct);

    connect(m_openFileAct,SIGNAL(triggered()),this,SLOT(openFile()));
    //connect(m_openEditorAct,SIGNAL(triggered()),this,SLOT(openEditor()));    
    connect(m_newFileAct,SIGNAL(triggered()),this,SLOT(newFile()));
    connect(m_newFileWizardAct,SIGNAL(triggered()),this,SLOT(newFileWizard()));
    connect(m_renameFileAct,SIGNAL(triggered()),this,SLOT(renameFile()));
    connect(m_removeFileAct,SIGNAL(triggered()),this,SLOT(removeFile()));
    connect(m_newFolderAct,SIGNAL(triggered()),this,SLOT(newFolder()));
    connect(m_renameFolderAct,SIGNAL(triggered()),this,SLOT(renameFolder()));
    connect(m_removeFolderAct,SIGNAL(triggered()),this,SLOT(removeFolder()));
    connect(m_openShellAct,SIGNAL(triggered()),this,SLOT(openShell()));
    connect(m_setRootAct,SIGNAL(triggered()),this,SLOT(setFolderToRoot()));
    connect(m_cdupAct,SIGNAL(triggered()),this,SLOT(cdUp()));
    connect(m_openExplorerAct,SIGNAL(triggered()),this,SLOT(openExplorer()));
    connect(m_viewGodocAct,SIGNAL(triggered()),this,SLOT(viewGodoc()));
    connect(m_loadFolderAct,SIGNAL(triggered()),this,SLOT(loadFolderProject()));

    //QDockWidget *dock = m_liteApp->dockManager()->addDock(m_widget,tr("File Browser"));
    //connect(dock,SIGNAL(visibilityChanged(bool)),this,SLOT(visibilityChanged(bool)));
    m_toolWindowAct = m_liteApp->toolWindowManager()->addToolWindow(Qt::LeftDockWidgetArea,m_widget,"filesystem",tr("File System"),true);
    connect(m_toolWindowAct,SIGNAL(toggled(bool)),this,SLOT(visibilityChanged(bool)));
    connect(m_treeView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(doubleClickedTreeView(QModelIndex)));
    connect(m_filterCombo,SIGNAL(activated(QString)),this,SLOT(activatedFilter(QString)));
    connect(m_rootCombo,SIGNAL(activated(QString)),this,SLOT(activatedRoot(QString)));
    connect(m_syncAct,SIGNAL(triggered(bool)),this,SLOT(syncFileModel(bool)));
    connect(m_liteApp->editorManager(),SIGNAL(currentEditorChanged(LiteApi::IEditor*)),this,SLOT(currentEditorChanged(LiteApi::IEditor*)));
    connect(m_treeView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(treeViewContextMenuRequested(QPoint)));

    QString root = m_liteApp->settings()->value("FileBrowser/root",m_fileModel->myComputer().toString()).toString();
    addFolderToRoot(root);
    bool b = m_liteApp->settings()->value("FileBrowser/synceditor",true).toBool();
    if (b) {
        m_syncAct->setChecked(true);
    }
}
예제 #30
0
void TestFileFuncs::onEnter()
{
    FileUtilsDemo::onEnter();
    auto s = Director::getInstance()->getWinSize();
    auto sharedFileUtils = FileUtils::getInstance();

    int x = s.width/2,
        y = s.height/5;
    Label* label = nullptr;

    std::string filename = "__test.test";
    std::string filename2 = "__newtest.test";
    std::string filepath = sharedFileUtils->getWritablePath() + filename;
    std::string content = "Test string content to put into created file";
    std::string msg;

    FILE *out = fopen(filepath.c_str(), "w");
    fputs(content.c_str(), out);
    fclose(out);

    // Check whether file can be created
    if (sharedFileUtils->isFileExist(filepath))
    {
        label = Label::createWithSystemFont("Test file '__test.test' created", "", 20);
        label->setPosition(x, y * 4);
        this->addChild(label);

        // getFileSize Test
        long size = sharedFileUtils->getFileSize(filepath);
        msg = StringUtils::format("getFileSize: Test file size equals %ld", size);
        label = Label::createWithSystemFont(msg, "", 20);
        label->setPosition(x, y * 3);
        this->addChild(label);

        // renameFile Test
        if (sharedFileUtils->renameFile(sharedFileUtils->getWritablePath(), filename, filename2))
        {
            label = Label::createWithSystemFont("renameFile: Test file renamed to  '__newtest.test'", "", 20);
            label->setPosition(x, y * 2);
            this->addChild(label);

            // removeFile Test
            filepath = sharedFileUtils->getWritablePath() + filename2;
            if (sharedFileUtils->removeFile(filepath))
            {
                label = Label::createWithSystemFont("removeFile: Test file removed", "", 20);
                label->setPosition(x, y * 1);
                this->addChild(label);
            }
            else
            {
                label = Label::createWithSystemFont("removeFile: Failed to remove test file", "", 20);
                label->setPosition(x, y * 1);
                this->addChild(label);
            }
        }
        else
        {
            label = Label::createWithSystemFont("renameFile: Failed to rename test file to  '__newtest.test', further test skipped", "", 20);
            label->setPosition(x, y * 2);
            this->addChild(label);
        }
    }
    else
    {
        label = Label::createWithSystemFont("Test file can not be created, test skipped", "", 20);
        label->setPosition(x, y * 4);
        this->addChild(label);
    }
}