Example #1
0
KXmlCommandAdvancedDlg::KXmlCommandAdvancedDlg(TQWidget *parent, const char *name)
: TQWidget(parent, name)
{
	m_xmlcmd = 0;

	m_command = new TQLineEdit(this);
	m_view = new TDEListView(this);
	m_view->addColumn("");
	m_view->header()->hide();
	m_view->setSorting(-1);
	m_apply = new TQToolButton(this);
	m_apply->setIconSet( TQApplication::reverseLayout()? SmallIconSet( "forward" ) : SmallIconSet("back"));
	m_addgrp = new TQToolButton(this);
	m_addgrp->setIconSet(SmallIconSet("folder"));
	m_addopt = new TQToolButton(this);
	m_addopt->setIconSet(SmallIconSet("document"));
	m_delopt = new TQToolButton(this);
	m_delopt->setIconSet(SmallIconSet("editdelete"));
	m_up = new TQToolButton(this);
	m_up->setIconSet(SmallIconSet("up"));
	m_down = new TQToolButton(this);
	m_down->setIconSet(SmallIconSet("down"));
	m_dummy = new TQWidget(this);
	m_desc = new TQLineEdit(m_dummy);
	m_name = new TQLineEdit(m_dummy);
	m_type = new TQComboBox(m_dummy);
	m_type->insertItem(i18n("String"));
	m_type->insertItem(i18n("Integer"));
	m_type->insertItem(i18n("Float"));
	m_type->insertItem(i18n("List"));
	m_type->insertItem(i18n("Boolean"));
	m_format = new TQLineEdit(m_dummy);
	m_default = new TQLineEdit(m_dummy);
	TQLabel	*m_namelab = new TQLabel(i18n("&Name:"), m_dummy);
	TQLabel	*m_desclab = new TQLabel(i18n("&Description:"), m_dummy);
	TQLabel	*m_formatlab = new TQLabel(i18n("&Format:"), m_dummy);
	TQLabel	*m_typelab = new TQLabel(i18n("&Type:"), m_dummy);
	TQLabel	*m_defaultlab = new TQLabel(i18n("Default &value:"), m_dummy);
	TQLabel	*m_commandlab = new TQLabel(i18n("Co&mmand:"), this);
	m_namelab->setBuddy(m_name);
	m_desclab->setBuddy(m_desc);
	m_formatlab->setBuddy(m_format);
	m_typelab->setBuddy(m_type);
	m_defaultlab->setBuddy(m_default);
	m_commandlab->setBuddy(m_command);
	m_persistent = new TQCheckBox( i18n( "&Persistent option" ), m_dummy );

	TQGroupBox	*gb = new TQGroupBox(0, Qt::Horizontal, i18n("Va&lues"), m_dummy);
	m_stack = new TQWidgetStack(gb);
	TQWidget	*w1 = new TQWidget(m_stack), *w2 = new TQWidget(m_stack), *w3 = new TQWidget(m_stack);
	m_stack->addWidget(w1, 1);
	m_stack->addWidget(w2, 2);
	m_stack->addWidget(w3, 3);
	m_edit1 = new TQLineEdit(w1);
	m_edit2 = new TQLineEdit(w1);
	TQLabel	*m_editlab1 = new TQLabel(i18n("Minimum v&alue:"), w1);
	TQLabel	*m_editlab2 = new TQLabel(i18n("Ma&ximum value:"), w1);
	m_editlab1->setBuddy(m_edit1);
	m_editlab2->setBuddy(m_edit2);
	m_values = new TDEListView(w2);
	m_values->addColumn(i18n("Name"));
	m_values->addColumn(i18n("Description"));
	m_values->setAllColumnsShowFocus(true);
	m_values->setSorting(-1);
	m_values->setMaximumHeight(110);
	m_addval = new TQToolButton(w2);
	m_addval->setIconSet(SmallIconSet("editcopy"));
	m_delval = new TQToolButton(w2);
	m_delval->setIconSet(SmallIconSet("editdelete"));
	TQToolTip::add(m_addval, i18n("Add value"));
	TQToolTip::add(m_delval, i18n("Delete value"));

	TQToolTip::add(m_apply, i18n("Apply changes"));
	TQToolTip::add(m_addgrp, i18n("Add group"));
	TQToolTip::add(m_addopt, i18n("Add option"));
	TQToolTip::add(m_delopt, i18n("Delete item"));
	TQToolTip::add(m_up, i18n("Move up"));
	TQToolTip::add(m_down, i18n("Move down"));

	KSeparator	*sep1 = new KSeparator(KSeparator::HLine, m_dummy);

	TQGroupBox	*gb_input = new TQGroupBox(0, Qt::Horizontal, i18n("&Input From"), this);
	TQGroupBox	*gb_output = new TQGroupBox(0, Qt::Horizontal, i18n("O&utput To"), this);
	TQLabel	*m_inputfilelab = new TQLabel(i18n("File:"), gb_input);
	TQLabel	*m_inputpipelab = new TQLabel(i18n("Pipe:"), gb_input);
	TQLabel	*m_outputfilelab = new TQLabel(i18n("File:"), gb_output);
	TQLabel	*m_outputpipelab = new TQLabel(i18n("Pipe:"), gb_output);
	m_inputfile = new TQLineEdit(gb_input);
	m_inputpipe = new TQLineEdit(gb_input);
	m_outputfile = new TQLineEdit(gb_output);
	m_outputpipe = new TQLineEdit(gb_output);

	m_comment = new KTextEdit( this );
	m_comment->setTextFormat(TQt::RichText );
	m_comment->setReadOnly(true);
	TQLabel *m_commentlab = new TQLabel( i18n( "Comment:" ), this );

	TQVBoxLayout	*l2 = new TQVBoxLayout(this, 0, KDialog::spacingHint());
	TQHBoxLayout	*l3 = new TQHBoxLayout(0, 0, KDialog::spacingHint());
	TQVBoxLayout	*l7 = new TQVBoxLayout(0, 0, 0);
	l2->addLayout(l3, 0);
	l3->addWidget(m_commandlab);
	l3->addWidget(m_command);
	TQHBoxLayout	*l0 = new TQHBoxLayout(0, 0, KDialog::spacingHint());
	TQGridLayout	*l10 = new TQGridLayout(0, 2, 2, 0, KDialog::spacingHint());
	l2->addLayout(l0, 1);
	l0->addLayout(TQT_TQLAYOUT(l10));
	l10->addMultiCellWidget(m_view, 0, 0, 0, 1);
	l10->addWidget(gb_input, 1, 0);
	l10->addWidget(gb_output, 1, 1);
	l10->setRowStretch(0, 1);
	l0->addLayout(l7);
	l7->addWidget(m_apply);
	l7->addSpacing(5);
	l7->addWidget(m_addgrp);
	l7->addWidget(m_addopt);
	l7->addWidget(m_delopt);
	l7->addSpacing(5);
	l7->addWidget(m_up);
	l7->addWidget(m_down);
	l7->addStretch(1);
	l0->addWidget(m_dummy, 1);
	TQGridLayout	*l1 = new TQGridLayout(m_dummy, 9, 2, 0, KDialog::spacingHint());
	l1->addWidget(m_desclab, 0, 0, Qt::AlignRight|Qt::AlignVCenter);
	l1->addWidget(m_desc, 0, 1);
	l1->addMultiCellWidget(sep1, 1, 1, 0, 1);
	l1->addWidget(m_namelab, 2, 0, Qt::AlignRight|Qt::AlignVCenter);
	l1->addWidget(m_name, 2, 1);
	l1->addWidget(m_typelab, 3, 0, Qt::AlignRight|Qt::AlignVCenter);
	l1->addWidget(m_type, 3, 1);
	l1->addWidget(m_formatlab, 4, 0, Qt::AlignRight|Qt::AlignVCenter);
	l1->addWidget(m_format, 4, 1);
	l1->addWidget(m_defaultlab, 5, 0, Qt::AlignRight|Qt::AlignVCenter);
	l1->addWidget(m_default, 5, 1);
	l1->addWidget( m_persistent, 6, 1 );
	l1->addMultiCellWidget(gb, 7, 7, 0, 1);
	l1->setRowStretch(8, 1);

	TQHBoxLayout	*l4 = new TQHBoxLayout(w2, 0, KDialog::spacingHint());
	l4->addWidget(m_values);
	TQVBoxLayout	*l6 = new TQVBoxLayout(0, 0, 0);
	l4->addLayout(l6);
	l6->addWidget(m_addval);
	l6->addWidget(m_delval);
	l6->addStretch(1);
	TQGridLayout	*l5 = new TQGridLayout(w1, 3, 2, 0, KDialog::spacingHint());
	l5->setRowStretch(2, 1);
	l5->addWidget(m_editlab1, 0, 0, Qt::AlignRight|Qt::AlignVCenter);
	l5->addWidget(m_editlab2, 1, 0, Qt::AlignRight|Qt::AlignVCenter);
	l5->addWidget(m_edit1, 0, 1);
	l5->addWidget(m_edit2, 1, 1);

	TQGridLayout	*l8 = new TQGridLayout(gb_input->layout(), 2, 2,
		KDialog::spacingHint());
	TQGridLayout	*l9 = new TQGridLayout(gb_output->layout(), 2, 2,
		KDialog::spacingHint());
	l8->addWidget(m_inputfilelab, 0, 0);
	l8->addWidget(m_inputpipelab, 1, 0);
	l8->addWidget(m_inputfile, 0, 1);
	l8->addWidget(m_inputpipe, 1, 1);
	l9->addWidget(m_outputfilelab, 0, 0);
	l9->addWidget(m_outputpipelab, 1, 0);
	l9->addWidget(m_outputfile, 0, 1);
	l9->addWidget(m_outputpipe, 1, 1);

	TQVBoxLayout	*l11 = new TQVBoxLayout(TQT_TQLAYOUT(gb->layout()));
	l11->addWidget(m_stack);

	TQVBoxLayout *l12 = new TQVBoxLayout( 0, 0, 0 );
	l2->addSpacing( 10 );
	l2->addLayout( l12 );
	l12->addWidget( m_commentlab );
	l12->addWidget( m_comment );

	connect(m_view, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotSelectionChanged(TQListViewItem*)));
	connect(m_values, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotValueSelected(TQListViewItem*)));
	connect(m_type, TQT_SIGNAL(activated(int)), TQT_SLOT(slotTypeChanged(int)));
	connect(m_addval, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddValue()));
	connect(m_delval, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveValue()));
	connect(m_apply, TQT_SIGNAL(clicked()), TQT_SLOT(slotApplyChanges()));
	connect(m_addgrp, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddGroup()));
	connect(m_addopt, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddOption()));
	connect(m_delopt, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveItem()));
	connect(m_up, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveUp()));
	connect(m_down, TQT_SIGNAL(clicked()), TQT_SLOT(slotMoveDown()));
	connect(m_command, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotCommandChanged(const TQString&)));
	connect(m_view, TQT_SIGNAL(itemRenamed(TQListViewItem*,int)), TQT_SLOT(slotOptionRenamed(TQListViewItem*,int)));
	connect(m_desc, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_name, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_format, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_default, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_edit1, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_edit2, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(slotChanged()));
	connect(m_type, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChanged()));
	connect(m_addval, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
	connect(m_delval, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
	connect( m_persistent, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( slotChanged() ) );
	m_dummy->setEnabled(false);
	viewItem(0);

	/**
	 * Add some short help for the normal (non expert) user
	 */
	TQWhatsThis::add( m_name, i18n(
				"An identification string. Use only alphanumeric characters except spaces. "
				"The string <b>__root__</b> is reserved for internal use." ) );
	TQWhatsThis::add( m_namelab, TQWhatsThis::textFor( m_name ) );
	TQWhatsThis::add( m_desc, i18n(
				"A description string. This string is shown in the interface, and should "
				"be explicit enough about the role of the corresponding option." ) );
	TQWhatsThis::add( m_desclab, TQWhatsThis::textFor( m_desc ) );
	TQWhatsThis::add( m_type, i18n(
				"The type of the option. This determines how the option is presented "
				"graphically to the user." ) );
	TQWhatsThis::add( m_typelab, TQWhatsThis::textFor( m_type ) );
	TQWhatsThis::add( m_format, i18n(
				"The format of the option. This determines how the option is formatted "
				"for inclusion in the global command line. The tag <b>%value</b> can be used "
				"to represent the user selection. This tag will be replaced at run-time by a "
				"string representation of the option value." ) );
	TQWhatsThis::add( m_formatlab, TQWhatsThis::textFor( m_format ) );
	TQWhatsThis::add( m_default, i18n(
				"The default value of the option. For non persistent options, nothing is "
				"added to the command line if the option has that default value. If this "
				"value does not correspond to the actual default value of the underlying "
				"utility, make the option persistent to avoid unwanted effects." ) );
	TQWhatsThis::add( m_defaultlab, TQWhatsThis::textFor( m_default ) );
	TQWhatsThis::add( m_persistent, i18n(
				"Make the option persistent. A persistent option is always written to the "
				"command line, whatever its value. This is useful when the chosen default "
				"value does not match with the actual default value of the underlying utility." ) );
	TQWhatsThis::add( m_command, i18n(
				"The full command line to execute the associated underlying utility. This "
				"command line is based on a mechanism of tags that are replaced at run-time. "
				"The supported tags are:<ul>"
				"<li><b>%filterargs</b>: command options</li>"
				"<li><b>%filterinput</b>: input specification</li>"
				"<li><b>%filteroutput</b>: output specification</li>"
				"<li><b>%psu</b>: the page size in upper case</li>"
				"<li><b>%psl</b>: the page size in lower case</li></ul>" ) );
	TQWhatsThis::add( m_commandlab, TQWhatsThis::textFor( m_command ) );
	TQWhatsThis::add( m_inputfile, i18n(
				"Input specification when the underlying utility reads input data from a file. Use "
				"the tag <b>%in</b> to represent the input filename." ) );
	TQWhatsThis::add( m_inputfilelab, TQWhatsThis::textFor( m_inputfile ) );
	TQWhatsThis::add( m_outputfile, i18n(
				"Output specification when the underlying utility writes output data to a file. Use "
				"the tag <b>%out</b> to represent the output filename." ) );
	TQWhatsThis::add( m_outputfilelab, TQWhatsThis::textFor( m_outputfile ) );
	TQWhatsThis::add( m_inputpipe, i18n(
				"Input specification when the underlying utility reads input data from its "
				"standard input." ) );
	TQWhatsThis::add( m_inputpipelab, TQWhatsThis::textFor( m_inputpipe ) );
	TQWhatsThis::add( m_outputpipe, i18n(
				"Output specification when the underlying utility writes output data to its "
				"standard output." ) );
	TQWhatsThis::add( m_outputpipelab, TQWhatsThis::textFor( m_outputpipe ) );
	TQWhatsThis::add( m_comment, i18n(
				"A comment about the underlying utility, which can be viewed by the user "
				"from the interface. This comment string supports basic HTML tags like "
				"&lt;a&gt;, &lt;b&gt; or &lt;i&gt;." ) );
	TQWhatsThis::add( m_commentlab, TQWhatsThis::textFor( m_comment ) );

	resize(660, 200);
}
Example #2
0
MainWindow::MainWindow(QWidget *parent) :
        QWidget(parent) {
    this->setWindowTitle("环境变量编辑器");
    /***************************************************
     全局布局控制
     */
    hblMain = new QHBoxLayout(this);
    vblRight = new QVBoxLayout(this);
    vblLeft = new QVBoxLayout(this);
    hblMain->addLayout(vblLeft);
    hblMain->addLayout(vblRight);
    /*******************************************************
     左侧布局
     */
    lbTableView = new QLabel("当前系统环境变量:", this);
    vblLeft->addWidget(lbTableView);
    tvValueList = new QTableView();
    vblLeft->addWidget(tvValueList);
    lbDetailTittle = new QLabel("变量信息:", this);
    vblLeft->addWidget(lbDetailTittle);
    lbPathDetail = new QLabel("变量信息:", this);
    vblLeft->addWidget(lbPathDetail);
    lbPathDetail->setGeometry(QRect(328, 240, 329, 27 * 4));  //四倍行距
    lbPathDetail->setWordWrap(true);  //自动换行
    lbPathDetail->setAlignment(Qt::AlignTop);
    /*******************************************************
     右侧布局
     */
    lbPathDescribe = new QLabel("Path设置:", this);
    vblRight->addWidget(lbPathDescribe);
    pbShowPath = new QPushButton("显示Path信息");  //显示path
    vblRight->addWidget(pbShowPath);
    pbEiditPath = new QPushButton("编辑Path路径");  //修改path
    vblRight->addWidget(pbEiditPath);

    //*****************************************************************

    lbBackDescribe = new QLabel("环境适配:");
    vblRight->addWidget(lbBackDescribe);
    pbSetBack = new QPushButton("备份当前环境");  //备份环境
    vblRight->addWidget(pbSetBack);
    pbUseBack = new QPushButton("还原到指定环境");  //还原环境
    vblRight->addWidget(pbUseBack);
    pbCheckIN = new QPushButton("导入特定环境变量");  //导入环境
    vblRight->addWidget(pbCheckIN);
    pbCheckOut = new QPushButton("导出指定环境变量"); //导出环境
    vblRight->addWidget(pbCheckOut);

    //*****************************************************************

    lbEiditDescribe = new QLabel("变量操作:");
    vblRight->addWidget(lbEiditDescribe);
    pbNewValue = new QPushButton("新建环境变量");  //新建变量
    vblRight->addWidget(pbNewValue);
    pbEiditValue = new QPushButton("编辑选中变量");  //编辑变量
    vblRight->addWidget(pbEiditValue);
    pbDelValue = new QPushButton("删除选中变量");  //删除变量
    vblRight->addWidget(pbDelValue);

    //*****************************************************************
    lbEiditFunction = new QLabel(" ");
    vblRight->addWidget(lbEiditFunction);
    pbAbout = new QPushButton("关于…");//关于
    vblRight->addWidget(pbAbout);
    pbExit = new QPushButton("退出"); //退出
    vblRight->addWidget(pbExit);

    /******************************************
     //        环境变量池
     */
    //显示变量
    slotRefrehValue();

    //通过是否可以新建环境变量判断是否以管理员身份启动
    reg->setValue("testAdminPermissions", "test");
    if (reg->value("testAdminPermissions", false).toBool()) {

        reg->remove("testAdminPermissions");
        isAdimin = true;
        //判断back目录是否存在,若没有提示用户备份!
        QDir dir;
        if (!dir.exists("./back/")) {
            switch (QMessageBox::information(this, "备份提醒",
                    "程序当前目录下找不到back文件夹,您可能从未对环境变量进行备份,为了保证操作安全,强烈建议您备份当前环境变量以减少误操作所带来的困扰!",
                    "立即备份!", "暂不需要!", 0, 1)) {
            case 0:
                slotSetBack();
                break;
            case 1:
                break;

            }

        }
    } else {
        QMessageBox::information(NULL, "未获得UAC管理员权限",
                "未使用UAC管理员权限开启本程序,由于Windows系统的限制,你可能只能查看变量内容而无法对其编辑");
        isAdimin = false;

    }

    //显示选中变量概要
    connect(tvValueList, SIGNAL(clicked(QModelIndex)), this,
            SLOT(slotGetClickedLine()));

    //槽
    //显示Path信息
    connect(pbShowPath, SIGNAL(clicked()), this, SLOT(slotShowPath()));
    //添加按钮槽
    connect(pbNewValue, SIGNAL(clicked()), this, SLOT(slotCreateWindow()));
    connect(pbEiditValue, SIGNAL(clicked()), this, SLOT(slotEiditWindow()));
    connect(pbEiditPath, SIGNAL(clicked()), this, SLOT(slotPathWindow()));

    //删除按钮槽
    connect(pbDelValue, SIGNAL(clicked()), this, SLOT(slotRemoveValue()));
    //备份
    connect(pbSetBack, SIGNAL(clicked()), this, SLOT(slotSetBack()));
    //还原
    connect(pbUseBack, SIGNAL(clicked()), this, SLOT(SlotGetBackWindow()));
    //导出
    connect(pbCheckOut, SIGNAL(clicked()), this, SLOT(slotExportWindow()));
    //导入
    connect(pbCheckIN, SIGNAL(clicked()), this, SLOT(slotImportWindow()));
    //退出
    connect(pbExit, SIGNAL(clicked()), this, SLOT(close()));
    //关于
    connect(pbAbout, SIGNAL(clicked()), this, SLOT(slotAboutWindow()));
}