void ordersfrm::contmenu() { QMenu* contextMenu = new QMenu( this ); Q_CHECK_PTR( contextMenu ); QAction* edititem = new QAction( tr("&Edit entry"), this ); connect(edititem , SIGNAL(triggered()), this, SLOT(editentry())); contextMenu->addAction(edititem); QAction* delitem = new QAction( tr("&Delete entry"), this ); connect(delitem , SIGNAL(triggered()), this, SLOT(deleteentry())); contextMenu->addAction(delitem); contextMenu->exec( QCursor::pos() ); delete contextMenu; }
int ordersfrm::init() { int r = this->checkrights(); if(r == 1) btnadd->setEnabled(FALSE); if(r==0) QMessageBox::information(0, tr("Authorization Required..."), tr("You are not authorized to open this modul\n\nPlease contact your Administrator")); treeindex->header()->setResizeMode(0, QHeaderView::Stretch); treeindex->setColumnWidth(1, 50); treeindex->setColumnHidden(2, TRUE); treemain->setColumnWidth(0, 40); vars v; QStringList sgeo = v.loadgeo(this->objectName()); if(sgeo.size() > 0 ) { if(sgeo[0] == "1") this->setWindowState(this->windowState() ^ Qt::WindowMaximized); this->setGeometry(sgeo[1].toInt(), sgeo[2].toInt(), sgeo[3].toInt(), sgeo[4].toInt()); } lbluser->setText(username); progbar->setMaximum(1); progbar->setValue(1); this->countentries(); connect(treeindex, SIGNAL(itemClicked ( QTreeWidgetItem*, int)), this, SLOT(loadentries())); connect(btnadd, SIGNAL(released()), this, SLOT(newentry())); connect(btnedit, SIGNAL(released()), this, SLOT(editentry())); connect(btndelete, SIGNAL(released()), this, SLOT(deleteentry())); connect(btncompleted, SIGNAL(released()), this, SLOT(complete())); connect(treemain, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contmenu())); connect(btnclose, SIGNAL(released()), this, SLOT(close())); return r; }
// creates all menus void WMain::createMenus() { fileMenu=new QMenu(this); wordMenu=new QMenu(this); testMenu=new QMenu(this); helpMenu=new QMenu(this); newAction=new QAction(tr("&New"), this); newAction->setShortcuts(QKeySequence::New); newAction->setStatusTip(tr("Create new dictionary")); openAction=new QAction(tr("&Open..."), this); openAction->setShortcuts(QKeySequence::Open); openAction->setStatusTip(tr("Open dictionary")); saveAction=new QAction(tr("&Save"), this); saveAction->setShortcuts(QKeySequence::Save); saveAction->setStatusTip(tr("Save dictionary")); saveasAction=new QAction(tr("&Save as..."), this); saveasAction->setShortcuts(QKeySequence::SaveAs); saveasAction->setStatusTip(tr("Save dictionary as")); printAction=new QAction(tr("&Print"), this); printAction->setShortcuts(QKeySequence::Print); printAction->setStatusTip(tr("Print dictionary")); settingsAction=new QAction(tr("&Settings"), this); settingsAction->setShortcut(QKeySequence("Ctrl+B")); settingsAction->setStatusTip(tr("Settings")); quitAction=new QAction(tr("&Quit"), this); quitAction->setShortcut(QKeySequence("Ctrl+Q")); quitAction->setStatusTip(tr("Quit dicto")); addAction=new QAction(tr("&Add..."), this); addAction->setShortcut(Qt::Key_Insert); addAction->setStatusTip(tr("Add new word")); editAction=new QAction(tr("&Edit..."), this); editAction->setStatusTip(tr("Edit current word")); deleteAction=new QAction(tr("&Delete"), this); deleteAction->setShortcut(Qt::Key_Delete); deleteAction->setStatusTip(tr("Delete current word")); sortAction=new QAction(tr("&Sort"), this); sortAction->setShortcut(QKeySequence("Ctrl+A")); sortAction->setStatusTip(tr("Sort dictionary")); testAction=new QAction(tr("&Test..."), this); testAction->setShortcut(QKeySequence("Ctrl+T")); testAction->setStatusTip(tr("Prepare test")); examAction=new QAction(tr("&Exam..."), this); examAction->setShortcut(QKeySequence("Ctrl+E")); examAction->setStatusTip(tr("Prepare exam")); statsAction=new QAction(tr("&Statistics..."), this); statsAction->setShortcut(QKeySequence("Ctrl+W")); statsAction->setStatusTip(tr("Show statistics")); aboutAction=new QAction(tr("&About"), this); aboutAction->setStatusTip(tr("About dicto")); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newAction); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); fileMenu->addAction(saveasAction); fileMenu->addAction(printAction); fileMenu->addSeparator(); for (int i = 0; i < 10/*maxRecentFiles*/; ++i) { recentFilesActions[i] = new QAction(this); recentFilesActions[i]->setVisible(false); fileMenu->addAction(recentFilesActions[i]); connect(recentFilesActions[i], SIGNAL(triggered()),this, SLOT(openRecentFile())); } updateRecentFileActions(); fileMenu->addSeparator(); fileMenu->addAction(settingsAction); fileMenu->addSeparator(); fileMenu->addAction(quitAction); wordMenu = menuBar()->addMenu(tr("&Words")); wordMenu->addAction(addAction); wordMenu->addAction(editAction); wordMenu->addAction(deleteAction); wordMenu->addSeparator(); wordMenu->addAction(sortAction); testMenu = menuBar()->addMenu(tr("&Test")); testMenu->addAction(testAction); testMenu->addAction(examAction); testMenu->addSeparator(); testMenu->addAction(statsAction); helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutAction); connect(newAction, SIGNAL(triggered()), this, SLOT(newfile())); connect(openAction, SIGNAL(triggered()), this, SLOT(openfile())); connect(saveAction, SIGNAL(triggered()), this, SLOT(savefile())); connect(saveasAction, SIGNAL(triggered()), this, SLOT(saveas())); connect(printAction, SIGNAL(triggered()), this, SLOT(print())); connect(settingsAction, SIGNAL(triggered()), this, SLOT(show_settings())); connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); connect(addAction, SIGNAL(triggered()), this, SLOT(addentry())); connect(editAction, SIGNAL(triggered()), this, SLOT(editentry())); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteentry())); connect(sortAction, SIGNAL(triggered()), this, SLOT(sortall())); connect(testAction, SIGNAL(triggered()), this, SLOT(preparetest())); connect(examAction, SIGNAL(triggered()), this, SLOT(prepareexam())); connect(statsAction, SIGNAL(triggered()), this, SLOT(stats())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(about())); }
// WMain constructor WMain::WMain(QWidget *parent) : QMainWindow(parent) { // set window properties resize(400, 400); setWindowTitle(tr("dicto")); setWindowIcon(QIcon(ICON)); centerWidgetOnScreen(this); setAttribute(Qt::WA_DeleteOnClose); // set random seed srand(time(0)); //create widgets mainWidget = new QWidget(this); setCentralWidget(mainWidget); searchBar = new QLineEdit; listWidget = new QListWidget; questionLabel = new QLabel(tr("Test!"), this); answerLabel = new QLabel(tr("Answer"), this); answerEdit = new QLineEdit; submitWordButton = new QPushButton(tr("OK"), this); cancelTestButton = new QPushButton(tr("End test"), this); examStatusLabel = new QLabel; tableWidget = new QTableWidget; submitExamButton = new QPushButton(tr("Submit exam"), this); cancelExamButton = new QPushButton(tr("Cancel exam"), this); progressBar = new QProgressBar; createMenus(); createTrayIcon(); // initialize widgets //QFont font; //font.setPointSize(20); //font.setBold(true); //questionLabel->setFont(font); //questionLabel->setTextFormat(Qt::RichText); questionLabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); questionLabel->setWordWrap(true); QFont questionFont; questionFont.setBold(true); questionLabel->setFont(questionFont); answerLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop); answerLabel->setWordWrap(true); tableWidget->setColumnCount(2); tableWidget->horizontalHeader()->hide(); tableWidget->verticalHeader()->hide(); tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); tableWidget->horizontalHeader()->setStretchLastSection(true); progressBar->setMinimum(0); // initialize members cDocument = new CDocument ; printer = new QPrinter; mode = normalMode; parent = 0; maxRecentFiles = QSettings("dicto.ini", QSettings::IniFormat).value("general/max_recent_files").value<int>(); // add layout QVBoxLayout *mainLayout=new QVBoxLayout(mainWidget); QVBoxLayout *normalLayout=new QVBoxLayout(); normalLayout->addWidget(searchBar); normalLayout->addWidget(listWidget); mainLayout->addLayout(normalLayout); QVBoxLayout *testLayout=new QVBoxLayout(); testLayout->addWidget(questionLabel); testLayout->addWidget(answerLabel); testLayout->addWidget(answerEdit); testLayout->addWidget(submitWordButton); testLayout->addWidget(cancelTestButton); mainLayout->addLayout(testLayout); QVBoxLayout *examLayout=new QVBoxLayout(); examLayout->addWidget(examStatusLabel); examLayout->addWidget(tableWidget); examLayout->addWidget(submitExamButton); examLayout->addWidget(cancelExamButton); mainLayout->addLayout(examLayout); mainWidget->setLayout(mainLayout); statusBar()->addPermanentWidget(progressBar); //update widgets updateStatusbar(); setMode(mode); // create shortcuts QShortcut *submitShortcut=new QShortcut(Qt::Key_Return, this); connect(submitShortcut, SIGNAL(activated()), this, SLOT(check())); QShortcut *hintShortcut=new QShortcut(QKeySequence("Ctrl+H"), this); connect(hintShortcut, SIGNAL(activated()), this, SLOT(hint())); QShortcut *findShortcut=new QShortcut(QKeySequence("Ctrl+f"), this); connect(findShortcut, SIGNAL(activated()), this, SLOT(search())); // connect signals and slots connect(searchBar, SIGNAL(textChanged(QString)), this, SLOT(updateList())); connect(listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(editentry())); connect(submitWordButton, SIGNAL(clicked()), this, SLOT(check())); connect(cancelTestButton, SIGNAL(clicked()), this, SLOT(canceltest())); connect(cancelExamButton, SIGNAL(clicked()), this, SLOT(cancelexam())); connect(submitExamButton, SIGNAL(clicked()), this, SLOT(checkexam())); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayactivated(QSystemTrayIcon::ActivationReason))); statusBar()->showMessage(tr("Dicto version %1").arg(VERSION)); }
int call_modify (int argc, char **argv) { struct ds_modifyentry_arg mod_arg; struct DSError error; struct entrymod *emnew, *ems_append(), *modify_avs(); Attr_Sequence as, #ifdef TURBO_DISK fget_attributes (), #else get_attributes (), #endif temp, trail = NULLATTR; AV_Sequence avst = NULLAV; extern AttributeType at_objectclass; extern int parse_status; Entry entry_ptr; FILE *fd; char draft_flag = FALSE; char noedit_flag = FALSE; int x; DN moddn; char *home; RDN new_rdn; struct list_element *start = 0 ; struct list_element *last ; struct list_element *l_temp ; /* char add = FALSE ; char rem = FALSE ; */ if ((argc = service_control (OPT, argc, argv, &mod_arg.mea_common)) == -1) return; mod_arg.mea_changes = NULLMOD; new_draft = FALSE; if (home = getenv ("DISHDRAFT")) strcpy (fname, home); else if (dad_flag) { strcpy (fname, "/tmp/dishXXXXXX"); unlink (mktemp (fname)); } else if (home = getenv ("HOME")) sprintf (fname, "%s/.dishdraft", home); else strcpy (fname, "./.dishdraft"); for (x=1; x<argc; x++) { if (test_arg (argv[x], "-draft",1)) { draft_flag = 1; shuffle_up (argc--,argv,x); if (x == argc) { ps_printf (OPT, "Draft file name missing\n"); Usage (argv[0]); return; } strcpy (fname, argv[x]); shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-newdraft",2)) { new_draft = TRUE; shuffle_up (argc--,argv,x--); } else if (test_arg (argv[x], "-noedit",3)) { noedit_flag = TRUE; shuffle_up (argc--,argv,x--); } else if (move (argv[x]) == OK) shuffle_up (argc--,argv,x--); else if (test_arg(argv[x], "-remove", 3)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to remove missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 0 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } else if (test_arg(argv[x], "-add", 2)) { shuffle_up (argc--, argv, x); if (x == argc) { ps_printf(OPT, "Attribute to insert missing\n") ; Usage(argv[0]) ; return ; } l_temp = (struct list_element *) malloc (sizeof(struct list_element)) ; l_temp->mod = (char *) malloc ((unsigned)(strlen(argv[x]) + 1)); strcpy (l_temp->mod, argv[x]) ; l_temp->add = 1 ; l_temp->next = 0 ; if (start == 0) { start = last = l_temp ; } else { last->next = l_temp ; last = l_temp ; } shuffle_up (argc--,argv,x--); } } if (dad_flag && (draft_flag || noedit_flag)) { ps_printf (OPT, "operation not allowed when using directory assistance server!\n"); return; } /* read attributes we want to modify */ if ((argc = read_cache_aux (argc, argv, FALSE, &mod_arg.mea_common)) <0 ) return; if (argc != 1) { ps_printf (OPT,"Unknown option %s\n",argv[1]); Usage (argv[0]); return; } if (start != 0) { if (build_modify(start, &mod_arg) == NOTOK) { return ; } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { return ; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name ; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ return ; } if (!draft_flag) { if (mod_template (fname,noedit_flag) != OK) return; noedit_flag = FALSE; } else { new_draft = TRUE; /* Ugh ! */ mod_template ("/dev/null",TRUE); } if (! noedit_flag) if (editentry (1, argv) != OK) { make_old (fname,draft_flag); return; } /* now parse the files */ if ((fd = fopen (fname, "r")) == (FILE *) NULL) { ps_printf (OPT, "Can't open draft entry %s\n", fname); return; } entry_ptr = get_default_entry (NULLENTRY); #ifdef TURBO_DISK entry_ptr->e_attributes = fget_attributes (fd); #else entry_ptr->e_attributes = get_attributes (fd); #endif fclose (fd); if (parse_status != 0) return; mod_arg.mea_object = dn; for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent) ; entry_ptr->e_name = rdn_cpy (moddn->dn_rdn); /* add rdn as attribute */ for (new_rdn = entry_ptr->e_name; new_rdn != NULLRDN; new_rdn = new_rdn->rdn_next) { avst = avs_comp_new (AttrV_cpy (&new_rdn->rdn_av)); temp = as_comp_new (AttrT_cpy (new_rdn->rdn_at), avst, NULLACL_INFO); entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp); } for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; trail = as->attr_link; as->attr_link = NULLATTR; temp = current_entry->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) { /* found it - does it need changing ? */ if (avs_cmp (as->attr_value, temp->attr_value) != 0) emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type); break; } if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_ADDATTRIBUTE; emnew->em_what = as_cpy(as); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); as->attr_link = trail; } /* remove attribute missing in new entry */ for (as = current_entry->e_attributes; as != NULLATTR; as = as->attr_link) { emnew = NULLMOD; temp = entry_ptr->e_attributes; for (; temp != NULLATTR; temp = temp->attr_link) if (AttrT_cmp (as->attr_type, temp->attr_type) == 0) break; if (temp == NULLATTR) { emnew = em_alloc (); emnew->em_type = EM_REMOVEATTRIBUTE; emnew->em_what = as_comp_new(as->attr_type,NULLAV,NULLACL_INFO); emnew->em_next = NULLMOD; } if (emnew != NULLMOD) mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew); } if (mod_arg.mea_changes == NULLMOD) { ps_print (RPS, "The draft entry and the entry for "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\nare exactly the same - no change made!!!\n"); entry_free (entry_ptr); make_old (fname,draft_flag); return; } if (rebind () != OK) { entry_free (entry_ptr); return; } /* * If this operation is time-stamped, it may have expired while the user * was editing the entry. Re-calculate the time-stamp. Modify is the only * dish command where this needs to be done. */ if ((mod_arg.mea_common.ca_security != (struct security_parms *) 0) && (mod_arg.mea_common.ca_security->sp_time != NULLCP)) { char *new_version(); free(mod_arg.mea_common.ca_security->sp_time); mod_arg.mea_common.ca_security->sp_time = new_version(); } /* If security parameters are present, take this to mean that strong * authentication is required. This disallows 'parms + no signature' * (pointless) and 'signature + no parms' (security risk). */ if (mod_arg.mea_common.ca_security != (struct security_parms *) 0) { extern struct SecurityServices *dsap_security; mod_arg.mea_common.ca_sig = (dsap_security->serv_sign)((caddr_t)&mod_arg, _ZModifyEntryArgumentDataDAS, &_ZDAS_mod); } while (ds_modifyentry (&mod_arg, &error) != DS_OK) { if (dish_error (OPT, &error) == 0) { entry_free (entry_ptr); return; } mod_arg.mea_object = error.ERR_REFERRAL.DSE_ref_candidates->cr_name; } ps_print (RPS, "Modified "); dn_print (RPS, dn, EDBOUT); ps_print (RPS, "\n"); delete_cache (dn); /* re-cache when next read */ entry_free (entry_ptr); ems_part_free (mod_arg.mea_changes); make_old (fname,draft_flag); }