Chain *prepend(Chain *n, Object *data) { Chain *aChain = newChain(); aChain->value = data; incrementRefCount(data); if (n != NULL) { aChain->next = n; } n = aChain; #ifdef DEBUG printf("Prepending:: %p\n", n); #endif return n; }
QString KisImportExportManager::importDocument(const QString& url, const QString& documentMimeType, KisImportExportFilter::ConversionStatus& status) { // Find the mime type for the file to be imported. QString typeName(documentMimeType); QUrl u(url); QMimeType t; if (documentMimeType.isEmpty()) { QMimeDatabase db; db.mimeTypeForFile(u.path(), QMimeDatabase::MatchExtension); if (t.isValid()) typeName = t.name(); } m_graph.setSourceMimeType(typeName.toLatin1()); // .latin1() is okay here (Werner) if (!m_graph.isValid()) { bool userCancelled = false; warnFile << "Can't open " << typeName << ", trying filter chooser"; if (m_document) { if (!m_document->isAutoErrorHandlingEnabled()) { status = KisImportExportFilter::BadConversionGraph; return QString(); } QByteArray nativeFormat = m_document->nativeFormatMimeType(); QApplication::setOverrideCursor(Qt::ArrowCursor); KisFilterChooser chooser(0, KisImportExportManager::mimeFilter(nativeFormat, KisImportExportManager::Import, m_document->extraNativeMimeTypes()), nativeFormat, u); if (chooser.exec()) { QByteArray f = chooser.filterSelected().toLatin1(); if (f == nativeFormat) { status = KisImportExportFilter::OK; QApplication::restoreOverrideCursor(); return url; } m_graph.setSourceMimeType(f); } else userCancelled = true; QApplication::restoreOverrideCursor(); } if (!m_graph.isValid()) { errFile << "Couldn't create a valid graph for this source mimetype: " << typeName; importErrorHelper(typeName, userCancelled); status = KisImportExportFilter::BadConversionGraph; return QString(); } } KisFilterChain::Ptr chain(0); // Are we owned by a KisDocument? if (m_document) { QByteArray mimeType = m_document->nativeFormatMimeType(); QStringList extraMimes = m_document->extraNativeMimeTypes(); int i = 0; int n = extraMimes.count(); chain = m_graph.chain(this, mimeType); while (i < n) { QByteArray extraMime = extraMimes[i].toUtf8(); // TODO check if its the same target mime then continue KisFilterChain::Ptr newChain(0); newChain = m_graph.chain(this, extraMime); if (!chain || (newChain && newChain->weight() < chain->weight())) chain = newChain; ++i; } } else if (!d->importMimeType.isEmpty()) { chain = m_graph.chain(this, d->importMimeType); } else { errFile << "You aren't supposed to use import() from a filter!" << endl; status = KisImportExportFilter::UsageError; return QString(); } if (!chain) { errFile << "Couldn't create a valid filter chain!" << endl; importErrorHelper(typeName); status = KisImportExportFilter::BadConversionGraph; return QString(); } // Okay, let's invoke the filters one after the other m_direction = Import; // vital information! m_importUrl = url; // We want to load that file m_exportUrl.clear(); // This is null for sure, as embedded stuff isn't // allowed to use that method status = chain->invokeChain(); m_importUrl.clear(); // Reset the import URL if (status == KisImportExportFilter::OK) return chain->chainOutput(); return QString(); }
PjModeler::PjModeler(const QDir &dir, QWidget *parent, QSqlDatabase db) : QWidget(parent), dir(dir) { if( ( ! dir.exists("main.cpp")) && ! QFile::copy( ":/file/files/main.cpp", dir.absoluteFilePath("main.cpp")) ) { setEnabled(false); QMessageBox::critical(this,tr("Error"),"Failed to build the <b>main.cpp</b> file!",QMessageBox::Ok,QMessageBox::Ok); } //editor editor = new MainEditor; editor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); regionViewer = new QListView; regionViewer->setObjectName("RegionViewer"); regionModel = new QStandardItemModel(this); mdDebug = new MdDebug; paroutModel = new ParoutModel(dir,editor,db); paroutViewer = new ParoutView; titleLabel = new QLabel; titleLabel->setObjectName("TitleLabel"); titleLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); titleLabel->setText("Simulation Datas exist! (Read-Only Mode)"); editButton = new QToolButton; editButton->setText(tr("Enable Editing") ); editButton->setToolButtonStyle(Qt::ToolButtonTextOnly); editButton->setObjectName("Switcher"); editButton->setCheckable(true); connect(editButton, SIGNAL(toggled(bool)), this,SLOT(setReadWrite(bool)) ); nextButton = new QToolButton; nextButton->setIcon(QIcon(":/icon/images/next.png") ); nextButton->setText(tr("Next Page")); nextButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); nextButton->setToolTip(tr("Next Page")); nextButton->setObjectName("ToolButton"); addchainButton = new QToolButton; addchainButton->setText(tr("Chain")); addchainButton->setIcon(QIcon(":/icon/images/addchain.png") ); addchainButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); addchainButton->setToolTip(tr("New Chain")); addchainButton->setObjectName("ToolButton"); addoutputButton = new QToolButton; addoutputButton->setText(tr("Output")); addoutputButton->setIcon(QIcon(":/icon/images/addoutput.png") ); addoutputButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); addoutputButton->setToolTip(tr("New Output")); addoutputButton->setObjectName("ToolButton"); titleBar = new QToolBar; titleBar->setObjectName("TitleBar"); editAction = titleBar->addWidget(editButton); titleBar->addWidget(titleLabel); deleteAction = titleBar->addAction(QIcon(":/icon/images/delete.png"),tr("Delete"),this,SLOT(deleteExtraSelections())); deleteAction->setDisabled(true); undoAction = titleBar->addAction(QIcon(":/icon/images/undo.png"),tr("Undo"),editor,SLOT(undo())); undoAction->setDisabled(true); redoAction = titleBar->addAction(QIcon(":/icon/images/redo.png"),tr("Redo"),editor,SLOT(redo())); redoAction->setDisabled(true); saveAction = titleBar->addAction(QIcon(":/icon/images/save.png"),tr("Save"),this,SLOT(save()) ); saveAction->setDisabled(true); titleBar->addSeparator(); titleBar->addWidget(addchainButton); titleBar->addWidget(addoutputButton); titleBar->addSeparator(); titleBar->addWidget(nextButton); //left splitter QSplitter *spl = new QSplitter(Qt::Vertical); spl->addWidget(regionViewer); spl->addWidget(paroutViewer); //rigth splitter QSplitter *spr = new QSplitter(Qt::Vertical); spr->addWidget(editor); spr->addWidget(mdDebug->textOutput); QVBoxLayout *lr = new QVBoxLayout; lr->addWidget(spr); lr->addWidget(mdDebug); QHBoxLayout *bodyLayout = new QHBoxLayout; bodyLayout->addWidget(spl); bodyLayout->addLayout(lr); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0,0,0,0); mainLayout->setSpacing(0); mainLayout->addWidget(titleBar); mainLayout->addLayout(bodyLayout); QStringList conststrs; conststrs << "//!" << "for(unsigned long istep=0;istep<steps;++istep)"; QFile file( dir.absoluteFilePath("main.cpp")); // file.setPermissions( QFileDevice::WriteOwner); editor->setEnabled( file.open(QIODevice::ReadOnly)); editor->setPlainText( file.readAll()); editor->setConstStrings( conststrs); editor->updateEnv(); editor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); //region widget regionViewer->setModel(regionModel); regionViewer->setSelectionMode(QAbstractItemView::ExtendedSelection); regionViewer->setEditTriggers(QAbstractItemView::NoEditTriggers); readRegion(); //parout viewer. connect(paroutModel,SIGNAL(simulationExistence(bool)),this,SLOT(setReadOnlyMode(bool)) ); paroutModel->initialize(); paroutViewer->setEditTriggers(QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked); paroutViewer->setSelectionMode(QAbstractItemView::SingleSelection); paroutViewer->setContextMenuPolicy(Qt::ActionsContextMenu); paroutViewer->setIndentation(0); paroutViewer->setAlternatingRowColors(true); paroutViewer->header()->setSectionResizeMode(QHeaderView::ResizeToContents); paroutViewer->header()->setStretchLastSection(false); paroutViewer->header()->setMinimumSectionSize(15); paroutViewer->setModel(paroutModel); paroutDelegate = new ParoutDelegate(paroutViewer); paroutViewer->setItemDelegateForColumn(1,paroutDelegate); paroutViewer->resizeToContent(); connect(undoAction,SIGNAL(triggered()),this,SLOT(readRegion())); connect(redoAction,SIGNAL(triggered()),this,SLOT(readRegion())); connect(addchainButton,SIGNAL(clicked()),this,SLOT(newChain()) ); connect(addoutputButton,SIGNAL(clicked()),this,SLOT(newOutput()) ); connect(regionViewer->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)),this,SLOT(regionViewerSelectionChanged()) ); connect(nextButton,SIGNAL(clicked()),this,SIGNAL(switch2Analyse()) ); connect(editor,SIGNAL(undoAvailable(bool)),undoAction,SLOT(setEnabled(bool)) ); connect(editor,SIGNAL(redoAvailable(bool)),redoAction,SLOT(setEnabled(bool)) ); connect(editor,SIGNAL(blockCountChanged(int)),this,SLOT(highlightCurrentSelection()) ); connect(mdDebug,SIGNAL(runTriggered()),this,SLOT(debug()) ); connect(mdDebug,SIGNAL(exploreDebugFolder()),this,SLOT(exploreDebugFolder()) ); connect(editor,SIGNAL(modificationChanged(bool)),this,SLOT(slotModificationChanged(bool)) ); }
//reader int main(int argc, char *argv[]) { //setup URL and chainfile and beginnings of the struct char *url; char *chainfile; FILE *cfile_in; int number_ss = 0; list *first = newList(); // check to see how many arguments if (argc == 1) { fputs("Need at least a URL argument for awget!\n",stderr); exit(1); } else if (argc == 2) { url = argv[1]; chainfile = "chaingang.txt"; } else if (argc == 4) { if(strcmp(argv[2], "-c") == 0){ url = argv[1]; chainfile = argv[3]; } else if(strcmp(argv[1], "-c") == 0){ url = argv[3]; chainfile = argv[2]; } } else{ fputs("Command usage!\n", stderr); } //try to open chainfile cfile_in = fopen(chainfile, "r"); //if no file exist print error and exit if (cfile_in==NULL) { fputs("No chain file available!\n", stderr); exit(1); } //proceed to set up values fscanf(cfile_in,"%d", &number_ss); //read in file store ipaddresses and ports const char *ipaddresses[number_ss]; const char *ports[number_ss]; int count = 0; //portion memory for an array of strings while(count < number_ss) { ipaddresses[count] = malloc(20 *sizeof(char)); ports[count] = malloc(20 *sizeof(char)); count++; } count = 0; while ( count < number_ss) { fscanf(cfile_in,"%s %s",ipaddresses[count], ports[count]); count++; } fclose(cfile_in); count = 0; list *ptr = newList(); //set random address to connect to srand (time(NULL)); int picked_ss = (rand()%number_ss); //debug //picked_ss = 0; //now read in values and set up the structs int picked_ss_flag = picked_ss; while ( count < number_ss) { //fscanf(cfile_in,"%s %d",ipaddresses[count], &ports[count]); if(count == picked_ss_flag) { count++; //ignore picked server to pass on to ss this will reduce the list } else if(picked_ss_flag == 0) { first->addressLen = strlen(ipaddresses[count]); //char *cpy; first->IP_address = ipaddresses[count]; //sprintf(cpy, "%d",); first->portLen = strlen(ports[count]); first->port = ports[count]; first->next = newList(); ptr = first->next; count++; picked_ss_flag = number_ss + 1; } else if(count == 0) { first->addressLen = strlen(ipaddresses[count]); //char *cpy; first->IP_address = ipaddresses[count]; //sprintf(cpy, "%d",); first->portLen = strlen(ports[count]); first->port = ports[count]; first->next = newList(); ptr = first->next; count++; } else { ptr->addressLen = strlen(ipaddresses[count]); //char *cpy; ptr->IP_address = ipaddresses[count]; //sprintf(ptr->port, "%d",ports[count]); ptr->portLen = strlen(ports[count]); ptr->port = ports[count]; ptr->next = newList(); ptr = ptr->next; count++; } //printf("%s %d\n",ipaddresses[count], ports[count]); } //now we can create the Chain struct! Chain *chaingang = newChain(url,number_ss-1,first); //set up socket connection struct hostent *he; int port_number; char *ip_address; int sockfd, numbytes, ret; //char buf[MAXDATASIZE]; pthread_t rThread; struct sockaddr_in their_addr; // connector’s address information if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } ip_address = ipaddresses[picked_ss]; port_number = atoi(ports[picked_ss]); struct in_addr ipv4addr; inet_pton(AF_INET, ip_address, &ipv4addr); he = gethostbyaddr(&ipv4addr, sizeof(ipv4addr), AF_INET); their_addr.sin_family = AF_INET; // host byte order their_addr.sin_port = htons(port_number); // short, network byte order //their_addr.sin_addr.s_addr = inet_addr(ip_adress); their_addr.sin_addr = *((struct in_addr *)he->h_addr); bzero(&(their_addr.sin_zero), 8); // zero the rest of the struct if (connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } //serialize the chain int chainLength = chainSize(chaingang); char *buffer = (char *)malloc(chainLength); awgetPrint(chaingang,ip_address,port_number); serializeChain(chaingang,buffer); if (send(sockfd, buffer, chainSize(chaingang), 0) == -1) { perror("send"); } char *f_buffer = (char *)malloc(MAXDATASIZE); printf("waiting for file...\n"); int flag = 1; unsigned char file_buffer[MAXDATASIZE]; ret = recvfrom(sockfd, f_buffer, MAXDATASIZE, 0, NULL, NULL); if (ret < 0) { printf("Error receiving data!\n"); } printf("Received file <%s>\n", f_buffer); FILE *file_write; file_write = fopen(f_buffer, "wb"); while(flag){ ret = recvfrom(sockfd, file_buffer, MAXDATASIZE, 0, NULL, NULL); if (ret < 0) { printf("Error receiving data!\n"); } else if(file_buffer[0] == '*' && file_buffer[1] == '*' && file_buffer[2] == '*' && file_buffer[3] == '*'){ flag = 0; //printf("%s\n",file_buffer); //printf("bytes recieved:%d\n",strlen(file_buffer)); printf("Goodbye!\n"); } else{ //printf("%s\n",file_buffer); //printf("bytes recieved:%d\n",strlen(file_buffer)); fwrite(file_buffer , 1 , MAXDATASIZE, file_write ); } } fclose(file_write); close(sockfd); return 0; }