/** * @brief MainWindow::firstFile * @param parentIndex * @return QModelIndex */ QModelIndex MainWindow::firstFile(QModelIndex parentIndex) { QModelIndex index = parentIndex; int numRows = proxyModel.rowCount(parentIndex); for (int row = 0; row < numRows; ++row) { index = proxyModel.index(row, 0, parentIndex); if (model.fileInfo(proxyModel.mapToSource(index)).isFile()) { return index; } if (proxyModel.hasChildren(index)) { return firstFile(index); } } return index; }
LRESULT CALLBACK SimulatorWin::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (!_instance) return 0; switch (uMsg) { case WM_COMMAND: { if (HIWORD(wParam) == 0) { // menu WORD menuId = LOWORD(wParam); PlayerMenuItemWin *menuItem = _instance->_menuService->getItemByCommandId(menuId); if (menuItem) { AppEvent event("APP.EVENT", APP_EVENT_MENU); std::stringstream buf; buf << "{\"data\":\"" << menuItem->getMenuId().c_str() << "\""; buf << ",\"name\":" << "\"menuClicked\"" << "}"; event.setDataString(buf.str()); event.setUserData(menuItem); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } if (menuId == ID_HELP_ABOUT) { onHelpAbout(); } } break; } case WM_KEYDOWN: { if (wParam == VK_F5) { PlayerProtocol::getInstance()->relaunch(); } break; } case WM_COPYDATA: { PCOPYDATASTRUCT pMyCDS = (PCOPYDATASTRUCT) lParam; if (pMyCDS->dwData == 1) { const char *szBuf = (const char*)(pMyCDS->lpData); SimulatorWin::getInstance()->writeDebugLog(szBuf); break; } } case WM_DESTROY: { DragAcceptFiles(hWnd, FALSE); break; } case WM_DROPFILES: { HDROP hDrop = (HDROP)wParam; const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0); if (count > 0) { int fileIndex = 0; const UINT length = DragQueryFileW(hDrop, fileIndex, NULL, 0); WCHAR* buffer = (WCHAR*)calloc(length + 1, sizeof(WCHAR)); DragQueryFileW(hDrop, fileIndex, buffer, length + 1); char *utf8 = SimulatorWin::convertTCharToUtf8(buffer); std::string firstFile(utf8); CC_SAFE_FREE(utf8); DragFinish(hDrop); // broadcast drop event AppEvent forwardEvent("APP.EVENT.DROP", APP_EVENT_DROP); forwardEvent.setDataString(firstFile); Director::getInstance()->getEventDispatcher()->dispatchEvent(&forwardEvent); } } // WM_DROPFILES } return g_oldWindowProc(hWnd, uMsg, wParam, lParam); }
bool TarImpl::removeFiles( const QStringList& _files ) { if ( !ensureInMode( ArchiveImpl::Remove ) ) { qDebug( "Couldn't change mode for removeFile" ); return false; } Q_ASSERT( m_mode == ArchiveImpl::Remove ); // need to cut out the sections which apply to // files which need are to be removed. no // api on QIODevice to do this, so read into a // QByteArray, modify it, and write it back. QIODeviceCloser ioDevice( m_ioDevice, QIODevice::ReadOnly, m_ioDevice->openMode() ); // first gather the positions and sizes of any files to be removed std::vector< std::pair<int,int> > removals; if ( !firstFile() ) { // The archive is empty return false; } unsigned int toremove(0); QStringList files( _files ); while( true ) { const int index = files.indexOf( m_dev->fileName() ); if ( index != -1 ) { const tar::TarHeader& curInfo = tarDevice()->headerInfo(); // start position const int pos = curInfo.pos(); // size of entry (header+data+block padding) const int size = curInfo.totalSize(); removals.push_back( std::pair< int, int >(pos, size ) ); toremove += size; files.removeAt( index ); } // stop if there's nothing left to find if ( files.isEmpty() ) { break; } // Move on to the next file if ( !nextFile() ) { // We're out of files break; } } if ( removals.empty() ) { qWarning( "No matching files were found to be removed" ); return false; } ioDevice->reset(); QByteArray data = ioDevice->readAll(); ioDevice->close(); // \todo better to copy the files we want to keep into a new QByteArray or // cut out the files we don't want? could compare size of archive with amount to be // removed // track how much has been removed as this modifies the start pos for // each removal block unsigned int removed(0); std::vector< std::pair<int,int> >:: const_iterator I = removals.begin(); std::vector< std::pair<int,int> >:: const_iterator E = removals.end(); for ( ; I!=E; ++I ) { data.remove( I->first - removed, I->second ); removed += I->second; } Q_ASSERT( toremove == removed ); ioDevice->open( QIODevice::WriteOnly | QIODevice::Truncate ); ioDevice->write( data ); return true; }
/** * @brief MainWindow::selectFirstFile */ void MainWindow::selectFirstFile() { QModelIndex index = proxyModel.mapFromSource(model.setRootPath(passStore)); index = firstFile(index); ui->treeView->setCurrentIndex(index); }