Exemple #1
0
 def accept(self):
     if not self.ans:
         return error_dialog(self,
                             _('No recipients'),
                             _('You must select at least one recipient'),
                             show=True)
     QDialog.accept(self)
Exemple #2
0
 def accept(self):
     action = 'move'
     if self.existing_library.isChecked():
         action = 'existing'
     elif self.empty_library.isChecked():
         action = 'new'
     text = str(self.location.text()).strip()
     if not text:
         return error_dialog(self,
                             _('No location'),
                             _('No location selected'),
                             show=True)
     loc = os.path.abspath(text)
     if action == 'move':
         try:
             os.makedirs(loc)
         except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
     if not loc or not os.path.exists(loc) or not os.path.isdir(loc):
         if action == 'new' and not os.path.exists(loc):
             os.makedirs(loc)
         else:
             return error_dialog(self,
                                 _('Bad location'),
                                 _('%s is not an existing folder') % loc,
                                 show=True)
     if not self.check_action(action, loc):
         return
     self.location.save_history()
     self.perform_action(action, loc)
     QDialog.accept(
         self
     )  # Must be after perform action otherwise the progress dialog is not updated on windows
Exemple #3
0
 def accept(self):
     if self.trim_action.isEnabled():
         self.trim_action.trigger()
     if self.canvas.is_modified:
         self.image_data = self.canvas.get_image_data()
     self.cleanup()
     QDialog.accept(self)
Exemple #4
0
    def accept(self):
        txt = unicode_type(self.textbox.toPlainText()).rstrip()
        if self.coloring:
            if self.colored_field.currentIndex() == -1:
                error_dialog(self, _('No column chosen'),
                    _('You must specify a column to be colored'), show=True)
                return
            if not txt:
                error_dialog(self, _('No template provided'),
                    _('The template box cannot be empty'), show=True)
                return

            self.rule = (unicode_type(self.colored_field.itemData(
                                self.colored_field.currentIndex()) or ''), txt)
        elif self.iconing:
            rt = unicode_type(self.icon_kind.itemData(self.icon_kind.currentIndex()) or '')
            self.rule = (rt,
                         unicode_type(self.icon_field.itemData(
                                self.icon_field.currentIndex()) or ''),
                         txt)
        elif self.embleming:
            self.rule = ('icon', 'title', txt)
        else:
            self.rule = ('', txt)
        self.save_geometry()
        QDialog.accept(self)
Exemple #5
0
 def accept(self):
     self.prefs_for_persistence.set(self.name + '-geometry',
                                    bytearray(self.saveGeometry()))
     if hasattr(self, 'splitter'):
         self.prefs_for_persistence.set(
             self.name + '-splitter-state',
             bytearray(self.splitter.saveState()))
     QDialog.accept(self)
Exemple #6
0
 def accept(self):
     if self.treat_as_image.isChecked():
         url = self.url.text()
         if url.lower().split(':', 1)[0] in ('http', 'https'):
             error_dialog(self, _('Remote images not supported'), _(
                 'You must download the image to your computer, URLs pointing'
                 ' to remote images are not supported.'), show=True)
             return
     QDialog.accept(self)
Exemple #7
0
 def accept(self):
     self.save_category()
     for cat in sorted(self.categories.keys(), key=sort_key):
         components = cat.split('.')
         for i in range(0,len(components)):
             c = '.'.join(components[0:i+1])
             if c not in self.categories:
                 self.categories[c] = []
     QDialog.accept(self)
Exemple #8
0
 def accept(self):
     recs = GuiRecommendations()
     for w in self._groups_model.widgets:
         if not w.pre_commit_check():
             return
         x = w.commit(save_defaults=False)
         recs.update(x)
     self._recommendations = recs
     QDialog.accept(self)
Exemple #9
0
 def accept(self):
     un = unicode_type(self.username.text())
     if self.service.get('at_in_username', False) and '@' not in un:
         return error_dialog(
             self,
             _('Incorrect username'),
             _('%s needs the full email address as your username') %
             self.service['name'],
             show=True)
     QDialog.accept(self)
Exemple #10
0
 def accept(self):
     # Prevent the usual dialog accept mechanisms from working
     gprefs['metadata_single_gui_geom'] = bytearray(self.saveGeometry())
     self.identify_widget.save_state()
     if DEBUG_DIALOG:
         if self.stack.currentIndex() == 2:
             return QDialog.accept(self)
     else:
         if self.stack.currentIndex() == 1:
             return QDialog.accept(self)
Exemple #11
0
 def accept(self):
     newloc = unicode_type(self.loc.text())
     if not db_class().exists_at(newloc):
         error_dialog(self, _('No library found'),
                 _('No existing calibre library found at %s')%newloc,
                 show=True)
         return
     self.stats.rename(self.location, newloc)
     self.newloc = newloc
     QDialog.accept(self)
Exemple #12
0
 def accept(self):
     name = self.name.text()
     if not name or len(name) < 2 or not name.startswith('#'):
         return error_dialog(self, _('Invalid name'), _(
             'The color scheme name "%s" is invalid. It must start with a # and be at least two characters long.') % name, show=True)
     if name in self.existing_names:
         if not self.is_editing or name != self.scheme_name:
             return error_dialog(self, _('Invalid name'), _(
                 'A color scheme with the name "%s" already exists.') % name, show=True)
     QDialog.accept(self)
Exemple #13
0
 def accept(self):
     if self.stack.currentIndex() == 0:
         self.on_shutdown()
         return QDialog.accept(self)
     try:
         close = self.commit()
     except AbortCommit:
         return
     if close:
         self.on_shutdown()
         return QDialog.accept(self)
     self.hide_plugin()
Exemple #14
0
 def get_plugins(self):
     from calibre.gui2.dialogs.plugin_updater import (
         PluginUpdaterDialog, FILTER_UPDATE_AVAILABLE)
     d = PluginUpdaterDialog(self.parent(),
                             initial_filter=FILTER_UPDATE_AVAILABLE)
     d.exec()
     if d.do_restart:
         QDialog.accept(self)
         from calibre.gui2.ui import get_gui
         gui = get_gui()
         if gui is not None:
             gui.quit(restart=True)
Exemple #15
0
 def ok_clicked(self, *args):
     self.cover_pixmap = self.covers_widget.cover_pixmap()
     if self.stack.currentIndex() == 0:
         self.next_clicked()
         return
     if DEBUG_DIALOG:
         if self.cover_pixmap is not None:
             self.w = QLabel()
             self.w.setPixmap(self.cover_pixmap)
             self.stack.addWidget(self.w)
             self.stack.setCurrentIndex(2)
     else:
         QDialog.accept(self)
Exemple #16
0
    def accept(self):
        path = str(self.path.text())
        if not path:
            return error_dialog(self, _('Path not specified'), _(
                'You must specify the path to the OPML file to import'), show=True)
        with open(path, 'rb') as f:
            raw = f.read()
        self.recipes = tuple(import_opml(raw, self.preserve_groups.isChecked()))
        if len(self.recipes) == 0:
            return error_dialog(self, _('No feeds found'), _(
                'No importable RSS feeds found in the OPML file'), show=True)

        QDialog.accept(self)
    def accept(self):
        port = unicode_type(self.fixed_port.text())
        if not port:
            error_dialog(self,
                         _('Invalid port number'),
                         _('You must provide a port number.'),
                         show=True)
            return
        try:
            port = int(port)
        except:
            error_dialog(
                self,
                _('Invalid port number'),
                _('The port must be a number between 8000 and 65535.'),
                show=True)
            return

        if port < 8000 or port > 65535:
            error_dialog(
                self,
                _('Invalid port number'),
                _('The port must be a number between 8000 and 65535.'),
                show=True)
            return

        self.device_manager.set_option('smartdevice', 'password',
                                       unicode_type(self.password_box.text()))
        self.device_manager.set_option('smartdevice', 'autostart',
                                       self.autostart_box.isChecked())
        self.device_manager.set_option('smartdevice', 'use_fixed_port',
                                       self.use_fixed_port.isChecked())
        self.device_manager.set_option('smartdevice', 'port_number',
                                       unicode_type(self.fixed_port.text()))

        message = self.device_manager.start_plugin('smartdevice')

        if not self.device_manager.is_running('smartdevice'):
            error_dialog(
                self,
                _('Problem starting the wireless device'),
                _('The wireless device driver had problems starting. It said "%s"'
                  ) % message,
                show=True)
            self.device_manager.set_option('smartdevice', 'use_fixed_port',
                                           self.orig_fixed_port)
            self.device_manager.set_option('smartdevice', 'port_number',
                                           self.orig_port_number)
        else:
            QDialog.accept(self)
Exemple #18
0
 def accept(self):
     recs = GuiRecommendations()
     for w in self._groups_model.widgets:
         if not w.pre_commit_check():
             return
         x = w.commit(save_defaults=False)
         recs.update(x)
     self.opf_file, self.cover_file = self.mw.opf_file, self.mw.cover_file
     self._recommendations = recs
     if self.db is not None:
         recs['gui_preferred_input_format'] = self.input_format
         save_specifics(self.db, self.book_id, recs)
     self.break_cycles()
     QDialog.accept(self)
Exemple #19
0
 def accept(self, *args):
     tags = unicode_type(self.add_tags.text()).strip().split(',')
     tags = list(filter(None, [x.strip() for x in tags]))
     gprefs['add from ISBN tags'] = tags
     gprefs['add from ISBN dup check'] = self.check_for_existing
     self.set_tags = tags
     bad = set()
     for line in unicode_type(
             self.isbn_box.toPlainText()).strip().splitlines():
         line = line.strip()
         if not line:
             continue
         parts = line.split('>>')
         if len(parts) > 2:
             parts = [parts[0] + '>>'.join(parts[1:])]
         parts = [x.strip() for x in parts]
         if not parts[0]:
             continue
         isbn = check_isbn(parts[0])
         if isbn is not None:
             isbn = isbn.upper()
             if isbn not in self.isbns:
                 self.isbns.append(isbn)
                 book = {'isbn': isbn, 'path': None}
                 if len(parts) > 1 and parts[1] and \
                     os.access(parts[1], os.R_OK) and os.path.isfile(parts[1]):
                     book['path'] = parts[1]
                 self.books.append(book)
         else:
             bad.add(parts[0])
     if bad:
         if self.books:
             if not question_dialog(
                     self,
                     _('Some invalid ISBNs'),
                     _('Some of the ISBNs you entered were invalid. They will'
                       ' be ignored. Click "Show details" to see which ones.'
                       ' Do you want to proceed?'),
                     det_msg='\n'.join(bad),
                     show_copy_button=True):
                 return
         else:
             return error_dialog(
                 self,
                 _('All invalid ISBNs'),
                 _('All the ISBNs you entered were invalid. No books'
                   ' can be added.'),
                 show=True)
     QDialog.accept(self, *args)
Exemple #20
0
    def accept(self):
        disp = self.fm['display']
        values = []
        colors = []
        for i in range(0, self.table.rowCount()):
            v = str(self.table.item(i, 0).text())
            if not v:
                error_dialog(self, _('Empty value'),
                                   _('Empty values are not allowed'), show=True)
                return
            values.append(v)
            c = str(self.table.cellWidget(i, 1).currentText())
            if c:
                colors.append(c)

        l_lower = [v.lower() for v in values]
        for i,v in enumerate(l_lower):
            if v in l_lower[i+1:]:
                error_dialog(self, _('Duplicate value'),
                                   _('The value "{0}" is in the list more than '
                                     'once, perhaps with different case').format(values[i]),
                             show=True)
                return

        if colors and len(colors) != len(values):
            error_dialog(self, _('Invalid colors specification'), _(
                'Either all values or no values must have colors'), show=True)
            return

        disp['enum_values'] = values
        disp['enum_colors'] = colors
        self.db.set_custom_column_metadata(self.fm['colnum'], display=disp,
                                           update_last_modified=True)
        self.save_geometry()
        return QDialog.accept(self)
    def accept(self):
        n = str(self.vl_name.currentText()).strip()
        if not n:
            error_dialog(self.gui, _('No name'),
                         _('You must provide a name for the new Virtual library'),
                         show=True)
            return

        if n.startswith('*'):
            error_dialog(self.gui, _('Invalid name'),
                         _('A Virtual library name cannot begin with "*"'),
                         show=True)
            return

        if n in self.existing_names and n != self.editing:
            if not question_dialog(self.gui, _('Name already in use'),
                         _('That name is already in use. Do you want to replace it '
                           'with the new search?'),
                            default_yes=False):
                return

        v = str(self.vl_text.text()).strip()
        if not v:
            error_dialog(self.gui, _('No search string'),
                         _('You must provide a search to define the new Virtual library'),
                         show=True)
            return

        try:
            db = self.gui.library_view.model().db
            recs = db.data.search_getting_ids('', v, use_virtual_library=False, sort_results=False)
        except ParseException as e:
            error_dialog(self.gui, _('Invalid search'),
                         _('The search in the search box is not valid'),
                         det_msg=e.msg, show=True)
            return

        if not recs and not question_dialog(
                self.gui, _('Search found no books'),
                _('The search found no books, so the Virtual library '
                'will be empty. Do you really want to use that search?'),
                default_yes=False):
            return

        self.library_name = n
        self.library_search = v
        QDialog.accept(self)
Exemple #22
0
 def accept(self):
     if not self.current_library_book_id:
         d = error_dialog(self.gui, _('Match books'),
                          _('You must select a matching book'))
         d.exec()
         return
     mi = self.library_db.get_metadata(self.current_library_book_id,
                                       index_is_id=True,
                                       get_user_categories=False,
                                       get_cover=True)
     book = self.device_db[self.current_device_book_id]
     book.smart_update(mi, replace_metadata=True)
     self.gui.update_thumbnail(book)
     book.in_library_waiting = True
     self.view.model().current_changed(self.current_device_book_index,
                                       self.current_device_book_index)
     self.save_state()
     QDialog.accept(self)
Exemple #23
0
 def accept(self):
     if not self.name_is_ok:
         return error_dialog(self, _('No name specified'), _(
             'You must specify a name for the new file, with an extension, for example, chapter1.html'), show=True)
     tprefs['auto_link_stylesheets'] = self.link_css.isChecked()
     name = str(self.name.text())
     name, ext = name.rpartition('.')[0::2]
     name = (name + '.' + ext.lower()).replace('\\', '/')
     mt = guess_type(name)
     if not self.file_data:
         if mt in OEB_DOCS:
             self.file_data = template_for('html').encode('utf-8')
             if tprefs['auto_link_stylesheets']:
                 data = add_stylesheet_links(current_container(), name, self.file_data)
                 if data is not None:
                     self.file_data = data
             self.using_template = True
         elif mt in OEB_STYLES:
             self.file_data = template_for('css').encode('utf-8')
             self.using_template = True
     self.file_name = name
     QDialog.accept(self)
Exemple #24
0
 def accept(self):
     if not self.uw.isReadOnly():
         un = self.username
         if not un:
             return error_dialog(
                 self,
                 _('Empty username'),
                 _('You must enter a username'),
                 show=True
             )
         if un in self.user_data:
             return error_dialog(
                 self,
                 _('Username already exists'),
                 _(
                     'A user with the username {} already exists. Please choose a different username.'
                 ).format(un),
                 show=True
             )
         err = validate_username(un)
         if err:
             return error_dialog(self, _('Username is not valid'), err, show=True)
     p1, p2 = self.password, self.p2.text()
     if p1 != p2:
         return error_dialog(
             self,
             _('Password do not match'),
             _('The two passwords you entered do not match!'),
             show=True
         )
     if not p1:
         return error_dialog(
             self,
             _('Empty password'),
             _('You must enter a password for this user'),
             show=True
         )
     err = validate_password(p1)
     if err:
         return error_dialog(self, _('Invalid password'), err, show=True)
     return QDialog.accept(self)
Exemple #25
0
    def accept(self):
        col = unicode_type(self.column_name_box.text()).strip()
        if not col:
            return self.simple_error('', _('No lookup name was provided'))
        if col.startswith('#'):
            col = col[1:]
        if re.match(r'^\w*$', col) is None or not col[0].isalpha() or col.lower() != col:
            return self.simple_error('', _('The lookup name must contain only '
                    'lower case letters, digits and underscores, and start with a letter'))
        if col.endswith('_index'):
            return self.simple_error('', _('Lookup names cannot end with _index, '
                    'because these names are reserved for the index of a series column.'))
        col_heading = unicode_type(self.column_heading_box.text()).strip()
        coldef = self.column_types[self.column_type_box.currentIndex()]
        col_type = coldef['datatype']
        if col_type[0] == '*':
            col_type = col_type[1:]
            is_multiple = True
        else:
            is_multiple = False
        if not col_heading:
            return self.simple_error('', _('No column heading was provided'))

        db = self.parent.gui.library_view.model().db
        key = db.field_metadata.custom_field_prefix+col
        bad_col = False
        if key in self.parent.custcols:
            if not self.editing_col or \
                    self.parent.custcols[key]['colnum'] != self.orig_column_number:
                bad_col = True
        if bad_col:
            return self.simple_error('', _('The lookup name %s is already used')%col)

        bad_head = False
        for t in self.parent.custcols:
            if self.parent.custcols[t]['name'] == col_heading:
                if not self.editing_col or \
                        self.parent.custcols[t]['colnum'] != self.orig_column_number:
                    bad_head = True
        for t in self.standard_colheads:
            if self.standard_colheads[t] == col_heading:
                bad_head = True
        if bad_head:
            return self.simple_error('', _('The heading %s is already used')%col_heading)

        display_dict = {}

        default_val = (unicode_type(self.default_value.text()).strip()
                        if col_type != 'composite' else None)

        if col_type == 'datetime':
            if unicode_type(self.format_box.text()).strip():
                display_dict = {'date_format':unicode_type(self.format_box.text()).strip()}
            else:
                display_dict = {'date_format': None}
            if default_val:
                if default_val == _('Now'):
                    display_dict['default_value'] = 'now'
                else:
                    try:
                        tv = parse_date(default_val)
                    except:
                        tv = UNDEFINED_DATE
                    if tv == UNDEFINED_DATE:
                        return self.simple_error(_('Invalid default value'),
                                 _('The default value must be "Now" or a date'))
                    display_dict['default_value'] = default_val
        elif col_type == 'composite':
            if not unicode_type(self.composite_box.text()).strip():
                return self.simple_error('', _('You must enter a template for '
                           'composite columns'))
            display_dict = {'composite_template':unicode_type(self.composite_box.text()).strip(),
                            'composite_sort': ['text', 'number', 'date', 'bool']
                                        [self.composite_sort_by.currentIndex()],
                            'make_category': self.composite_make_category.isChecked(),
                            'contains_html': self.composite_contains_html.isChecked(),
                        }
        elif col_type == 'enumeration':
            if not unicode_type(self.enum_box.text()).strip():
                return self.simple_error('', _('You must enter at least one '
                            'value for enumeration columns'))
            l = [v.strip() for v in unicode_type(self.enum_box.text()).split(',') if v.strip()]
            l_lower = [v.lower() for v in l]
            for i,v in enumerate(l_lower):
                if v in l_lower[i+1:]:
                    return self.simple_error('', _('The value "{0}" is in the '
                    'list more than once, perhaps with different case').format(l[i]))
            c = unicode_type(self.enum_colors.text())
            if c:
                c = [v.strip() for v in unicode_type(self.enum_colors.text()).split(',')]
            else:
                c = []
            if len(c) != 0 and len(c) != len(l):
                return self.simple_error('', _('The colors box must be empty or '
                           'contain the same number of items as the value box'))
            for tc in c:
                if tc not in QColor.colorNames() and not re.match("#(?:[0-9a-f]{3}){1,4}",tc,re.I):
                    return self.simple_error('', _('The color {0} is unknown').format(tc))
            display_dict = {'enum_values': l, 'enum_colors': c}
            if default_val:
                if default_val not in l:
                    return self.simple_error(_('Invalid default value'),
                             _('The default value must be one of the permitted values'))
                display_dict['default_value'] = default_val
        elif col_type == 'text' and is_multiple:
            display_dict = {'is_names': self.is_names.isChecked()}
        elif col_type in ['int', 'float']:
            if unicode_type(self.format_box.text()).strip():
                display_dict = {'number_format':unicode_type(self.format_box.text()).strip()}
            else:
                display_dict = {'number_format': None}
            if default_val:
                try:
                    if col_type == 'int':
                        msg = _('The default value must be an integer')
                        tv = int(default_val)
                        display_dict['default_value'] = tv
                    else:
                        msg = _('The default value must be a real number')
                        tv = float(default_val)
                        display_dict['default_value'] = tv
                except:
                    return self.simple_error(_('Invalid default value'), msg)
        elif col_type == 'comments':
            display_dict['heading_position'] = unicode_type(self.comments_heading_position.currentData())
            display_dict['interpret_as'] = unicode_type(self.comments_type.currentData())
        elif col_type == 'rating':
            half_stars = bool(self.allow_half_stars.isChecked())
            display_dict['allow_half_stars'] = half_stars
            if default_val:
                try:
                    tv = int((float(default_val) if half_stars else int(default_val)) * 2)
                except:
                    tv = -1
                if tv < 0 or tv > 10:
                    if half_stars:
                        return self.simple_error(_('Invalid default value'),
                             _('The default value must be a real number between 0 and 5.0'))
                    else:
                        return self.simple_error(_('Invalid default value'),
                             _('The default value must be an integer between 0 and 5'))
                display_dict['default_value'] = tv
        elif col_type == 'bool':
            if default_val:
                tv = {_('Yes'): True, _('No'): False}.get(default_val, None)
                if tv is None:
                    return self.simple_error(_('Invalid default value'),
                             _('The default value must be "Yes" or "No"'))
                display_dict['default_value'] = tv

        if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
            display_dict['use_decorations'] = self.use_decorations.checkState()

        if default_val and 'default_value' not in display_dict:
            display_dict['default_value'] = default_val

        display_dict['description'] = self.description_box.text().strip()

        if not self.editing_col:
            self.parent.custcols[key] = {
                    'label':col,
                    'name':col_heading,
                    'datatype':col_type,
                    'display':display_dict,
                    'normalized':None,
                    'colnum':None,
                    'is_multiple':is_multiple,
                }
            self.parent.cc_column_key = key
        else:
            self.parent.custcols[self.orig_column_name]['label'] = col
            self.parent.custcols[self.orig_column_name]['name'] = col_heading
            # Remove any previous default value
            self.parent.custcols[self.orig_column_name]['display'].pop('default_value', None)
            self.parent.custcols[self.orig_column_name]['display'].update(display_dict)
            self.parent.custcols[self.orig_column_name]['*edited'] = True
            self.parent.custcols[self.orig_column_name]['*must_restart'] = True
            self.parent.cc_column_key = key
        QDialog.accept(self)
Exemple #26
0
    def accept(self):
        open_url(QUrl(get_download_url()))

        QDialog.accept(self)
Exemple #27
0
 def accept(self):
     self._format = self._formats[self.formats.currentRow()]
     return QDialog.accept(self)
Exemple #28
0
 def accept(self):
     dynamic.set(self.cfg_key + '__un',
                 unicode_type(self.gui_username.text()))
     dynamic.set(self.cfg_key + '__pw',
                 unicode_type(self.gui_password.text()))
     QDialog.accept(self)
Exemple #29
0
 def accept(self):
     try:
         self.restart_required = self.w.commit()
     except AbortCommit:
         return
     QDialog.accept(self)
 def accept(self, *args):
     for idx in self.fview.selectedIndexes():
         self.selected_formats.add(self.formats.fmt(idx))
     QDialog.accept(self, *args)